我正在启动一个非常简单的学习应用程序,我正在使用NSURLConnection,并且已经开始研究读取文件的内容,例如www.funnynews letter.tk/files/files.txt,并将它们作为字符串读取到Objective C中。
我想知道如何做到这一点并将保存的字符串打印到标签" label“上。
有人能帮我吗?
这是我当前的代码。
- (void) viewDidUnLoad
{
NSError* e;
NSString *str = [NSString stringWithContentsOfURL:@"http://funnynewsletter.tk/files/files.txt"];
if(e != nil) {
NSLog(@"Error");
}
label.text = self.str;
}这在第4行和第8行有错误。我不知道发生了什么。有人能帮上忙吗?
发布于 2012-11-29 12:38:53
您发送的是NSString而不是NSURL。
- (void) viewDidLoad
{
//NSError* e;
NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://funnynewsletter.tk/files/files.txt"]];
//if(e != nil) {
// NSLog(@"Error");
//}
label.text = str;
}试试这个。
https://stackoverflow.com/questions/13618838
复制相似问题