简体   繁体   中英

How to pass a third value in a cell to another table view controller

我有一个带有textLabeldetailTextLabelUITableViewController ,问题是我想传递一个具有URL “隐藏”第三个值,因此当我将行触摸到下一个UITableViewController ,可以使用委托didSelectRowAtIndexPath来获取URL,但是我该怎么做?

You can send a dictionary to the next TableView. Import the SecondTableView controller .h file into your FirstTableView controller and then reference the target dictionary. You will also need to implement prepareForSegue and call it in didSelectRowAtIndexPath. Something like this:

In didSelectRowAtIndexPath: (make sure to set the segue identifier in Storyboard if you are using it).

[self performSegueWithIdentifier:@"toSecondTableViewController" sender:nil];

In SecondTableViewController.h create your dictionary

@property (nonatomic, retain)NSMutableDictionary *selectedDictionary;

Make sure to synthesize this in the SecondTableViewController.m file.

and then in your 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM