[英]How to pass a third value in a cell to another table view controller
我有一个带有textLabel
和detailTextLabel
的UITableViewController
,问题是我想传递一个具有URL
“隐藏”第三个值,因此当我将行触摸到下一个UITableViewController
,可以使用委托didSelectRowAtIndexPath
来获取URL,但是我该怎么做?
You can send a dictionary to the next TableView. 您可以将字典发送到下一个TableView。 Import the SecondTableView controller .h file into your FirstTableView controller and then reference the target dictionary.
将SecondTableView控制器.h文件导入到FirstTableView控制器中,然后引用目标字典。 You will also need to implement prepareForSegue and call it in didSelectRowAtIndexPath.
您还需要实现prepareForSegue并在didSelectRowAtIndexPath中对其进行调用。 Something like this:
像这样:
In didSelectRowAtIndexPath: (make sure to set the segue identifier in Storyboard if you are using it). 在didSelectRowAtIndexPath中:(如果正在使用,请确保在Storyboard中设置segue标识符)。
[self performSegueWithIdentifier:@"toSecondTableViewController" sender:nil];
In SecondTableViewController.h create your dictionary 在SecondTableViewController.h中创建您的字典
@property (nonatomic, retain)NSMutableDictionary *selectedDictionary;
Make sure to synthesize this in the SecondTableViewController.m file. 确保在SecondTableViewController.m文件中进行合成。
and then in your FirstTableViewController 然后在您的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;
}
}
You can then reference keys in the selectedDictionary in your SecondTableViewController and get that URL. 然后,您可以在SecondTableViewController中的selectedDictionary中引用键并获取该URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.