如何从USL链接读取数据,并将其显示在我的textview上? URL链接内容仅包含普通文本
我正在使用:
NSString *userAgreementStringURL = [NSString stringWithFormat:@"%@/requestConfigurationData.php?ownerID=%@&view=userAgreement", serverURL, ownerID];
NSURL *userAgreementURL = [NSURL URLWithString:userAgreementStringURL];
NSURLRequest *userAgreementRequest = [NSURLRequest requestWithURL:userAgreementURL];
userAgreementData = [[NSMutableData alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
userAgreementConnection = [[NSURLConnection connectionWithRequest:userAgreementRequest delegate:self] retain];
[userAgreementTextView setText:[NSString stringWithContentsOfURL:@"http://medicinephone.com/dev2/visit/requestConfigurationData.php?ownerID=13&view=userAgreement" encoding:NSUTF8StringEncoding error:NULL]];
答案 0 :(得分:0)
[myTextView setText:[NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://apple.com" encoding:NSUTF8StringEncoding error:NULL]]];
一行代码,谢谢苹果。
编辑:忘了从字符串中创建一个NSURL。
答案 1 :(得分:0)
告诉我们你的代码。如果你正在尝试我认为你正在尝试将数组传递给文本视图的setText
方法将无效。您需要在此之前从数组中获取字符串。如果数组每个数组元素包含一个单词,则可能需要尝试使用componentsJoinedByString
。