NSArray聲明會引發錯誤,因爲「NSURL的可見@interface聲明瞭選擇器componentsseparatedbytring」。NSURL沒有可見的@interface聲明選擇器componentsseparatedbystring
NSURL *MyURL = [[NSBundle mainBundle]
URLForResource: @"artList" withExtension:@"txt"];
NSArray *lines = [MyURL componentsSeparatedByString:@"\n"]; // each line, adjust character for line endings
for (int i = 0; i < 10; i++) {
NSString *line;
//in lines;
NSLog(@"%@", [NSString stringWithFormat:@"line: %@", line]);
_wordDefBox.text = [NSString stringWithFormat:@"%@%@",_wordDefBox.text, lines];
}
'componentsSeparatedByString:'是一個'NSString'方法,而不是'NSURL'。我猜你想要的是:'+ stringWithContentsOfURL:encoding:error:',然後在其上使用'componentsSeparatedByString:'。 – Larme