Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSARRAY编码错误_Objective C_Uiscrollview - Fatal编程技术网

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);将内容输出到控制台的代码中?