我有 2 个包含名称和文件名的数组对象。就像这样:
name={"PRESENTATION FILE", "MEETING DOCUMENT", "REPORT"}
file={"item1.ppt", "item2.pdf", "item3.pdf"}
我在我的 TableViewCell 中使用这段代码来显示文档
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
Document * documentObject;
documentObject = [_all_documentArray objectAtIndex:indexPath.row];
cell.textLabel.text = documentObject.name;
NSString *doc_link =[[NSString alloc] initWithFormat:@"http://localhost/database/%@",documentObject.file];
NSURL *doc_url=[NSURL URLWithString:doc_link];
[[UIApplication sharedApplication] openURL:doc_url];
return cell;
}
当我这样做时,第一个链接会在我打开表格 View 后立即出现。我需要做什么才能打开与我选择的列表具有相同索引的链接?抱歉英语不好,提前致谢
最佳答案
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Document * documentObject;
documentObject = [_all_documentArray objectAtIndex:indexPath.row];
NSString *doc_link =[[NSString alloc] initWithFormat:@"http://localhost/database/%@",documentObject.file];
NSURL *doc_url=[NSURL URLWithString:doc_link];
[[UIApplication sharedApplication] openURL:doc_url];
}
关于ios - 在 UITableViewCell 中选择特定索引后在 safari 中打开链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25717711/