gpt4 book ai didi

ios - prepareForSegue 被调用两次,在演示过程中尝试呈现

转载 作者:技术小花猫 更新时间:2023-10-29 10:42:12 26 4
gpt4 key购买 nike

我是 ios 编程的新手,在这里问,但我一直访问!我很困惑为什么我会遇到这个问题,它编译没有错误,我已经检查并检查了我的 MainStoryboard 中的所有 socket 和标识符。

我有 2 个 UITableViewController,当用户在表中选择一个项目时,我将一个字符串从第一个传递到第二个,所以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 中

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

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

然后当我点击取消按钮返回到 firstTableview 并再次按下详细 View 时,它不再显示 null..

在进度 View 中,正确的字符串在结果中,正确的字符串在进度 View 中,正确的字符串

最佳答案

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

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

关于ios - prepareForSegue 被调用两次,在演示过程中尝试呈现 <UINavigationController>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14940738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com