我有一个NSTextView,其对象绑定到其数据源。我无法弄清楚如何干预a)保存更改,以及b)设置(或允许用户设置)字体。我在SO上看到了很多关于此的问题。
我尝试过这样的事情:
[[textView textStorage] setFont:[NSFont fontWithName:@"HelveticaNeue" size:13]];
我有一个textDidChange
方法 - 但它没有被调用......
-(void)textDidChange:(NSNotification *)notification
{
NSLog(@"%s", __FUNCTION__);
NSTextView *textView = [notification object];
[currentItem setValue:textView.string forKey:@"narrative"];
[currentItem setObject:[textView string] forKey:@"narrative"];
NSString *oldField = [currentItem objectForKey:@"narrative"];
[currentItem setObject:[textView string] forKey:textView.string];
[currentItem saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
// Revert state on save error.
[currentItem setObject:oldField forKey:@"narrative"];
textView.string = oldField;
}
}];
[[textView textStorage] setFont:[NSFont fontWithName:@"HelveticaNeue" size:14]];
[textView setNeedsDisplay:YES];
}
我对Cocoa绑定有些新意,所以任何想法都会受到赞赏..