繁体   English   中英

如何将单元格中的第三个值传递给另一个表视图控制器

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

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

您可以将字典发送到下一个TableView。 将SecondTableView控制器.h文件导入到FirstTableView控制器中,然后引用目标字典。 您还需要实现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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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