0

我目前有 2 个视图控制器:ViewControllerDetailViewController. 它们都不是表视图控制器,它们都只是视图控制器。但是,我确实有一张桌子,ViewController它在其他方面工作得很好。我想在DetailViewController选择单元格时选择/传递一个变量。

使用情节提要,我设置了一个从单元格到DetailViewController标识符的模态序列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):

- (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];
    }
}

但是我得到一个错误:Property 'tableView' not found on object type 'ViewController *'。我认为这是因为它不是表视图控制器?我怎样才能解决这个问题?或者我可以使用另一种方法来使用 segue 和传递变量(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath吗?

4

1 回答 1

0

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

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

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

于 2012-07-22T20:58:35.400 回答