Objective c 在NSArray的文本视图中显示文本
此方法可在AppDelagate中找到,加载我选择的文本文件,并将文本文件的上下文拆分为数组 我无法在调用的Objective c 在NSArray的文本视图中显示文本,objective-c,macos,nstextview,Objective C,Macos,Nstextview,此方法可在AppDelagate中找到,加载我选择的文本文件,并将文本文件的上下文拆分为数组 我无法在调用的self.textView中显示数组的内容 我不知道如何使用数组的每个成员更新文本视图 - (IBAction)loadButton:(id)sender { NSOpenPanel *panel = [NSOpenPanel openPanel]; if ([panel runModal] == NSFileHandlingPanelOKButton) {
self.textView
中显示数组的内容
我不知道如何使用数组的每个成员更新文本视图
- (IBAction)loadButton:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
if ([panel runModal] == NSFileHandlingPanelOKButton) {
NSURL *bookUrl = [panel URL];
NSString *contents = [NSString stringWithContentsOfURL: bookUrl encoding: NSASCIIStringEncoding error: NULL];
NSArray *loadedBook = [contents componentsSeparatedByString:@"#NP#"];
self.textView.value = loadedBook[0];
}
}
正确的方法是,它在NSText
中声明
您的代码应该是:
- (IBAction)loadButton:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
if ([panel runModal] == NSFileHandlingPanelOKButton) {
NSURL *bookUrl = [panel URL];
NSString *contents = [NSString stringWithContentsOfURL: bookUrl encoding: NSASCIIStringEncoding error: NULL];
NSArray *loadedBooks = [contents componentsSeparatedByString:@"#NP#"];
[self.textView setString:bookStr];
}
}
更新
看一看,要了解如何向NSScrollView添加文本,我不知道
textView.value
属性是什么。它不应该是textView.text
?textView.text不是我可以分配的属性。值是唯一一个我认为可以接近我需要的值。谷歌搜索“NSTextView如何更改文本”难吗?这是第一个结果:文本视图被声明为appdelegate.h文件@property(弱)IBMScrollView*textView中的属性;你究竟为什么要将NSScrollView对象命名为textView
?