gpt4 book ai didi

iphone - didSelectRowAtIndexPath 处的 PushViewController

转载 作者:行者123 更新时间:2023-12-03 20:56:17 26 4
gpt4 key购买 nike

我有以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
if (tvc == nil)
tvc = [[TopicViewController alloc] initWithNibName:@"TopicViewController" bundle:nil];
tvc.title = @"Topic";
tvc.topicId = [[results objectAtIndex:indexPath.row] objectForKey:@"id"];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:tvc animated:YES];
[tvc release];

}

因此,当我点击该行时,它可以显示此表格 View 。然后我按导航返回并选择不同的行,然后应用程序崩溃。我试图在控制台中查看是否有任何错误,但找不到任何错误。怎么了?

最佳答案

我相信你的 (tvc == nil) 返回 NO 因为你释放了 tvc 但没有将其设置为 nil 所以下次访问此方法时,你尝试将其作为 View Controller 推送而无需再次分配它,因此崩溃。

您可以删除 if (tvc == nil) 检查或释放 tvc,然后使用 [tvc release], tvc = nil; 将其设置为 nil。

另一种可能性是您的结果数组正在被释放。它在哪里初始化并且您是否为其声明了保留属性?如果是这样,您可以使用 [self.results objectAtIndex:...] 访问它,这将保证它将一直保留到您的 View Controller 被释放为止。

关于iphone - didSelectRowAtIndexPath 处的 PushViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5013245/

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