小编iPh*_*oob的帖子

从其他ViewController调用didSelectRowAtIndexPath不响应iPad

我想MasterViewController从detailViewController上的按钮更改表(in )中的选定行.我知道我不能打电话,didSelectRowAtIndexPath因为它是委托方法.我尝试过使用selectRowAtIndexPath但不会调用didSelectRowAtIndexPath也不会调用willSelectRowAtIndexPath方法.正如这里提到的,https: //stackoverflow.com/a/7496926/1050722 可以使用一些新方法,然后从另一个方法ViewController(detailViewController)调用该方法,但该方法应该如何?

这是一些代码:

MasterViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath   
{
    [self pushDetailViewController:indexPath];
}

-(void)pushDetailViewController:(NSIndexPath *)indexPath
{        
    if (!self.detailViewController) {
        self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    }
    [self.navigationController pushViewController:self.detailViewController animated:YES];
    NSLog(@"pushDetailviewC and index %@", indexPath);
}
Run Code Online (Sandbox Code Playgroud)

DetailViewController.m

-(IBAction)nextItem
{
    MasterViewController *mVc = [[MasterViewController alloc] init];
    [mVc pushDetailViewController:[NSIndexPath indexPathForRow:0 inSection:0]];
}
Run Code Online (Sandbox Code Playgroud)

有人能举个例子来解决这个问题吗?谢谢.

编辑:这是新代码

MasterViewController.m

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self pushDetailViewController:indexPath];

}

-(void)pushDetailViewController:(NSIndexPath *)indexPath{

    if …
Run Code Online (Sandbox Code Playgroud)

uitableview ipad ios

4
推荐指数
1
解决办法
4411
查看次数

标签 统计

ios ×1

ipad ×1

uitableview ×1