2011-08-07 33 views
3

有没有发布一些通知或以其他方式告诉NSTextView或任何可编辑元素何时自动更新了某些内容?自动更正通知

+0

为什么?一些背景可能会有帮助 – tjameson

回答

3

其实我已发现了如何使用NSTextView拼写检查委托方法来做到这一点:

- (NSArray *)textView:(NSTextView *)view didCheckTextInRange:(NSRange)range types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options results:(NSArray *)results orthography:(NSOrthography *)orthography wordCount:(NSInteger)wordCount { 
    for (NSTextCheckingResult *result in results) { 
     if (result.resultType == NSTextCheckingTypeCorrection) { 
      NSLog(@"autocomplete has occured! %@", result); 
     } 
    } 
    return results; 
} 
+0

不错的答案,非常方便。 –

2
+0

这听起来像我所需要的,但是当我订阅它时,它在自动更正发生时不会被调用。 – Joshua

+1

也许是一个错误?也许发布一些相关的代码供他人审查。 –

+0

我一直在订阅这样的通知:'[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(autocompleteOccurred :) name:NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification object:nil'''autocompleteOccured'方法只包含一个NSLog。然后在我的应用程序中使用NSTextView我导致自动更正,但我从来没有看到消息记录。 – Joshua