我想在单元格点击时打开一个特定的 URL。
我正在尝试使用对象来执行此操作,但它不起作用。字符串“url”获取(null)。
代码:
//setting object
[self.url2 addObject:@"http://google.nl"];
//method to select cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get your url, eg: NSString *url = yourArray[indexPath.row];
NSString *url = [NSString stringWithFormat:@"%@", [self.url2 objectAtIndex:indexPath.row]];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
这可能吗?
谢谢。
最佳答案
试试这个片段,
NSMutableArray *URLArray = [[NSMutableArray alloc] init];
[URLArray addObject:@"http://google.nl"];
NSString *URLString = [NSString stringWithFormat:@"%@",[URLArray objectAtIndex:indexPath.row]];
NSLog(@"URLString: %@",URLString.description);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLString] options:@{} completionHandler:nil];
你可以在 NSMutableArray
中添加 URLs
但要确保
URLArray.count == numberOfRowsInSection
以避免 NSRangeException
。
关于ios - 在表格 View 单元格上单击打开 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44660513/