我有一个 Controller 类,我从中调用模型类的方法。现在,从这个模型类方法中,我想连续更新 textView 对象,它是 Controller 类的数据成员。我在 Controller 类中有方法来编辑这个textView。我尝试从模型类方法创建 Controller 对象并编辑 textView。虽然我没有收到任何错误,但它没有在 textView 中显示文本。如何让模型类使用 Controller 类方法来连续显示文本..?是不是我正在创建一个本地 Controller 对象并引用它的textView而不是原始 Controller 对象。
Controller.m 文件:
- (void) notifyContentHasChanged:(NSInteger) block {
NSString *str;
str = [NSString stringWithFormat:@"Block Written Successfully: %d\n", block];
[data insertText:str];
}
模型.m 文件:
Controller * c = [[Controller alloc] init];
while (USB_SUCCESS(status)){
DfuBlockCnt++;
printf("\nBlocks Written Successfully: %d",DfuBlockCnt);
[c notifyContentHasChanged:DfuBlockCnt];
}
最佳答案
您应该考虑使用 KVO(键值观察),这样您就可以让观察者为您完成所有工作。
我想知道您与 NSTextView 的连接是否丢失 - 如果您尝试将消息传递给 Objective C 中的 nil 对象,它不会给您错误。
关于objective-c - Mac应用程序的MVC架构问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/323350/