iOS新手。
当我对参数进行硬编码,将其作为字符串传递给URLWithString时,情况有效:像这样 -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
UIApplication *ourApplication = [UIApplication sharedApplication];
NSURL *url = [NSURL URLWithString:@"http://files.parse.com/81b196c3-d103-4db1-bb6f-0c74acedfa8c/5f0718e2-a79a-454c-ae9c-082ba28a74-Kontractor_test2.pdf"];
[ourApplication openURL:url];
}
但是当我尝试添加一个object:方法然后将一个变量传递给URLWithString时:像这样
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [object objectForKey:@"link"];
NSString *fileURL;
fileURL = cell.textLabel.text;
UIApplication *ourApplication = [UIApplication sharedApplication];
NSURL *url = [NSURL URLWithString:fileURL];
[ourApplication openURL:url];
}
单击表格单元格时,模拟器不会启动浏览器。知道为什么会这样吗?谢谢
答案 0 :(得分:0)
您传递的网址必须不受模拟器支持(tel:,本地资源等)。