使用 UIViewController 中的表将变量传递给详细视图控制器(不是 UITableViewController !!) [英] Pass variable to a detail view controller using a table in UIViewController (not UITableViewController!!)

查看:50
本文介绍了使用 UIViewController 中的表将变量传递给详细视图控制器(不是 UITableViewController !!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有 2 个视图控制器:ViewControllerDetailViewController.它们都不是表视图控制器,它们都只是视图控制器.但是,我确实有一个关于 ViewController 的表格,它在其他方面很好用.我想在选择一个单元格时将一个变量传递给 DetailViewController.

I currently have 2 view controllers: ViewController and DetailViewController. Neither of them are Table View Controllers, they are both just View Controllers. However, I do have a table on ViewController which is otherwise working great. I want to segue/pass a variable to DetailViewController when a cell is selected.

使用故事板,我设置了一个从单元格到 DetailViewController 的模态转场,标识符为 toDetailView.

Using the storyboard I set up a modal segue from the cell to DetailViewController with the identifier toDetailView.

我尝试使用此方法将我的变量(在本例中称为 play)从 VC 传递到 DVC(通过 http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007416-Classes_RootViewController_m-DontLinkElementID_10):

I tried to use this method to pass my variable (in this example called play) from VC to DVC (via http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007416-Classes_RootViewController_m-DontLinkElementID_10):

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"toDetailView"]) {

        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        DetailViewController *detailViewController = [segue destinationViewController];
        detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
    }
}

但是我收到一个错误:在对象类型ViewController *"上找不到属性tableView".我认为这是因为它不是表视图控制器?我怎样才能解决这个问题?或者我可以使用另一种方法来使用 (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 来传递和传递变量吗?

However I get an error: Property 'tableView' not found on object type 'ViewController *'. I think this is because it's not a Table View Controller? How can I get around this? Or is there another method I could use to segue and pass the variable using (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath?

推荐答案

在 ViewController 上,创建一个这样的新属性:

On the ViewController, create a new property like that :

@property (nonatomic, assign) IBOutlet UITableView *tableView;

然后合成它.然后,在 Interface Builder 中,您应该能够将插座分配给您正在使用的 tableview.这应该可以解决问题

And synthesize it. Then, in Interface Builder, you should be able to assign the outlet to the tableview you are using. This should do the trick

这篇关于使用 UIViewController 中的表将变量传递给详细视图控制器(不是 UITableViewController !!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆