質問

だから私はuitableviewを持っています、そして、新しいuiviewcontrollerを開くために、セルはuistoryboardsegueに接続されています。セルをクリックした後 prepareForSegue Getが呼び出され、すべてが正常に機能します。

質問: 次の方法では、テーブルビューで選択したセルのインデックスパスが何であるかをどうすればわかりますか?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ObjectDetailViewController *mvc = [segue destinationViewController];
    // PassingObject *obj = [self.array objectAtIndex: ? ];
    mvc.passingObject = obj;
}
役に立ちましたか?

解決

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Assume self.view is the table view
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    DetailObject *detail = [self detailForIndexPath:path];
    [segue.destinationViewController setDetail:detail];
}

他のヒント

self.tableview indexpathforselectedrow]の代わりに(djplayerの回答を見てください)、[self.tableview indexpathforcell:sender]を使用できます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top