Objective c NSARRAY编码错误
有人注意到这个编码中有错误吗Objective c NSARRAY编码错误,objective-c,uiscrollview,Objective C,Uiscrollview,有人注意到这个编码中有错误吗 NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"]; NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:NULL]; practiceContent = [fileContents
NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:NULL];
practiceContent = [fileContents componentsSeparatedByString:@" "];
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(320,960);
myScrollView.pagingEnabled = FALSE;
myScrollView.scrollEnabled = TRUE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
UILabel *lblText = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
lblText.text = practiceContent;
[myScrollView addSubview:lblText];
[lblText release];
我正在尝试将text.txt中的文本传递到scrollview上的标签中…它在编译时不会显示任何错误
提前谢谢
practiceContent = [fileContents componentsSeparatedByString:@" "];
...
lblText.text = practiceContent;
practiceContent
是一个NSArray,但是lblText.text
需要一个NSString。你应该简单地写
lblText.text = fileContents;
编译器没有抱怨的原因可能是您将
practiceContent
声明为id
。如果类型为id
,编译器将无法执行编译时类型检查。是否尝试插入NSLog(@“\n TEXT CONTENTS:%@”,practiceContent);将内容输出到控制台的代码中?