prepareForSegue被调用两次,尝试呈现< UINavigationController>在进行演示时 [英] prepareForSegue getting called twice, with Attempt to present <UINavigationController> while presentation is in progress

查看:60
本文介绍了prepareForSegue被调用两次,尝试呈现< UINavigationController>在进行演示时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ios编程的新手,并在这里询问,但是我一直都在访问!我很困惑为什么会出现此问题,它编译时没有错误,并且我已经检查并检查了我的MainStoryboard中的所有插座和标识符.

I am new to ios programming and asking here, but I visit all the time! I am stumped at why I am getting this problem, it compiles with no errors and I have checked and checked all my outlets and identifiers in my MainStoryboard.

我有2个UITableViewControllers,当用户在表中选择一个项目时,我将字符串从第一个传递到第二个,所以在 FirstTableViewController.m

I have 2 UITableViewControllers, I am passing a string from the first to the second when the user selects an item in the table, so in FirstTableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int sel = indexPath.row;
    if (sel == 0) {
        _keyName = [NSString stringWithString:_string1];
        NSLog(@"the table was selected at cell 0, %@", _string1);
    }
    if (sel == 1) {
        _keyName = [NSString stringWithString:_string2];
    }
    // more code below...
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"ResultsSegue"])
    {
        UINavigationController *navigationController = segue.destinationViewController;
        ResultsViewController *rv = [[navigationController viewControllers] objectAtIndex:0];
        [rv setResults: _keyName];
        NSLog(@"in the progress view, %@", _keyName);
        //rv.delegate = (id)self;
        rv.delegate = self;            
    }
}

在我的ResultsViewController.m

And in my ResultsViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"in the results, %@", _results);
    NSLog(@"in the results view");
}

在NSlog读数中,我得到: ... 在进度视图中,(空) 在结果中,(空) 在进度视图中,正确的字符串" 警告:尝试呈现

然后,当我按下取消"按钮返回到firstTableview并再次按详细信息视图时,它不再显示为null.

In the NSlog readout I get: ... in the progress view, (null) in the results, (null) in the progress view, The Right String Warning: Attempt to present on

Then when I hit the cancel button to return to the firstTableview and press the detail view again it no longer shows null..

在进度视图中,正确的字符串 在结果中,正确的字符串 在进度视图中,正确的字符串"

in the progress view, The Right String in the results, The Right String in the progress view, The Right String

推荐答案

问题是在didSelectRowAtIndexPath之前调用了prepareForSegue.您应该只消除didSelectRowAtIndexPath方法,并在prepareForSegue中进行所有操作.您可以使用以下行获取所需的indexPath:

The problem is prepareForSegue is called before didSelectRowAtIndexPath. You should just eliminate the didSelectRowAtIndexPath method, and do everything in prepareForSegue. You can use the following line to get the indexPath you need:

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

这篇关于prepareForSegue被调用两次,尝试呈现< UINavigationController>在进行演示时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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