gpt4 book ai didi

objective-c - 将 TableViewCell 推送到另一个 ViewController 时出错

转载 作者:行者123 更新时间:2023-11-28 18:39:32 25 4
gpt4 key购买 nike

我试图将数据从 TableViewCell 传递到另一个 ViewController。但是另一个 ViewController 中没有显示数据。这是我的代码

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


PeripheralManager *objSelected=[device objectAtIndex:indexPath.row];

[self prepareForSegue:@"TableDetails" sender:objSelectedDevice];
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


if ([segue.identifier isEqualToString:@"TableDetails"])
{


DetailViewController *detail=segue.destinationViewController;
detail.dataArray=device;
}

}

错误信息

nested push animation can result in corrupted navigation bar
2012-10-24 12:01:39.805 [3182:707] nested push animation can result in corrupted navigation bar
2012-10-24 12:01:40.164 [3182:707] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-10-24 12:01:40.167 [3182:707] Finishing up a get navigation transition in an unexpected state. Navigation Bar subview tree might corrupted.

最佳答案

你不需要这个:

[self.navigationController pushViewController:mdc animated:YES];

这就是 Segue 会自动执行的操作

此外,您有 3 行将加载 View Controller - 请参阅下面的注释:

NSInteger row=[indexPath row];
NSString *value=[device objectAtIndex:row];
MeBleDetailViewController *mdc=[self.storyboard instantiateViewControllerWithIdentifier:@"MeBleDetailViewController"];
mdc.deviceName=value;
[self presentModalViewController:mdc animated:YES]; // Load ViewController
[UIView commitAnimations];
[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]]; // Load ViewController
[self.navigationController pushViewController:mdc animated:YES]; // Load ViewController

这就是您收到该错误的原因:nested push animation can result in corrupted navigation bar

此外,如果您已经配置了从表格单元格到另一个 View Controller 的 segue,那么您不需要在 didSelectRowAtIndexPath 方法中做任何事情。


编辑:

无论您希望推送的 View Controller 拥有什么数据 - 将其放在 prepareforSegue 方法中而不是 didSelectRowAtIndexPath

如果您创建一个从表格单元格到 View Controller 的转场,那么您不需要执行以下操作,因为此方法是以编程方式执行转场。

[self performSegueWithIdentifier:@"TableDetails"sender:[device objectAtIndex:indexPath.row]];

关于objective-c - 将 TableViewCell 推送到另一个 ViewController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13042932/

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