我有一个带有 textLabel
和 detailTextLabel
的 UITableViewController
,问题是我想传递一个比方说“隐藏”的第三个具有 URL
的值,因此当我将行触摸到下一个 UITableViewController
时,我可以使用委托(delegate) didSelectRowAtIndexPath
来获取 URL,但是如何才能我这样做?
最佳答案
您可以将字典发送到下一个TableView。将 SecondTableView Controller .h 文件导入到 FirstTableView Controller 中,然后引用目标字典。您还需要实现prepareForSegue并在didSelectRowAtIndexPath中调用它。像这样的事情:
在 didSelectRowAtIndexPath 中:(如果使用的话,请确保在 Storyboard 中设置 segue 标识符)。
[self performSegueWithIdentifier:@"toSecondTableViewController" sender:nil];
在 SecondTableViewController.h 中创建你的字典
@property (nonatomic, retain)NSMutableDictionary *selectedDictionary;
确保在 SecondTableViewController.m 文件中综合它。
然后在你的 FirstTableViewController
#import SecondTableViewController.h
//prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"toSecondTableViewController"])
{
//create the dictionary to store the information from the array
NSDictionary *dictionaryToPass;
//MainTable is your TableView in your TableViewController
NSIndexPath *indexpath = [self.MainTable indexPathForSelectedRow];
NSLog(@"IndexPath is: %@",indexpath);
//load correct information based on indexpath selected
dictionaryToPass = [array objectAtIndex:indexpath.row];
//create the view for the segue
SecondTableViewController *secondTable = segue.destinationViewController;
//pass the dictionary
seriesTable.selectedDictionary = dictionaryToPass;
}
}
然后,您可以在 SecondTableViewController 中引用 selectedDictionary 中的键并获取该 URL。
关于iphone - 如何将单元格中的第三个值传递给另一个 TableView Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14244632/