简体   繁体   English

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

[英]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. 您可以将字典发送到下一个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.

相关问题 如何将值从表视图单元格传递到视图控制器 - how to pass the value from table view cell to view controller 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 表视图单元格到另一个视图控制器 - Table view cell to another view controller 如何从表单元格调用/传递数组值到视图? - How to call/pass an array value from a table cell into a view? 如何将字符串值从一个视图控制器传递到另一个视图控制器 - how to pass a string value from one view controller to another view controller 在另一个视图控制器中单击删除按钮后,如何在表格视图中删除单元格数据并重新排列 - how to delete a cell data in a table view and rearranging after clicking the delete button in another view controller 如何将注释标题传递给另一个视图控制器 - How to pass annotation title to another view controller 从表格单元格中的文本从一个View控制器获取到另一个View控制器 - Getting text from table cell from one View controller to another View controller 将字符串值从一个视图控制器传递给另一个 - Pass a string value from one view controller to another 无法将值从一个视图控制器传递到情节提要上的另一个 - Not able to pass value from one view controller to another on storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM