iphone - 如何将单元格中的第三个值传递给另一个 TableView Controller

标签 iphone ios objective-c xcode cocoa-touch

我有一个带有 textLabeldetailTextLabelUITableViewController ,问题是我想传递一个比方说“隐藏”的第三个具有 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/

相关文章:

ios - Swift 3 中 "asset"的使用不明确

objective-c - -[UICIColor colorSpaceName] : unrecognized selector sent to instance

ios - 使用 AudioKit 将音频文件作为麦克风输入播放 - 用于 iOS 模拟器听写测试

objective-c - rootViewController 需要澄清

ios - UIScrollView 只能用一根手指滚动

iphone - 如何公开类成员或如何实现对那些成员起作用的方法

ios - 当应用程序处于后台且手机处于振动状态时,某些警报应用程序(例如 Alarmy)如何能够在 iPhone 上播放声音

ios - 从容器 View 获取数据

iphone - Plist Array 到 NSArray 没有对象

ios - 获取 Facebook 好友返回空