iOS实现文件浏览器按相同的视图控制器显示错误



我需要使用uitaiteViewController创建文件浏览器函数。

我将数据加载到表视图中,如果用户在索引路径处选择的行是文件夹,

我想推动相同的数据结构和UITATEVIEW,并使用Reload TableView更改保存视图控制器中的数据显示。

所以我尝试添加

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

在didSelectRowatIndExpath委托法中。

所有方法代码:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     [self.navigationController pushViewController:self animated:YES];
 }

但我得到的错误日志低于

 Terminating app due to uncaught exception 'NSInvalidArgumentException', 
 reason: 'Pushing the same view controller instance more than once is not supported

i使用pushViewController,因为iOS可以显示回到预览文件标题并具有动画。

有人可以教我如何解决问题或具有更好的功能实施方法吗?

非常感谢。

可能的解决方案 - 它是分配您类的新实例,然后将其推入NavigationController,而不是推self

类似的东西:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     YourController *controller = [[YourController alloc] init]
     [self.navigationController pushViewController: controller animated:YES];
 }

您可以使用此方法:

[self.navigationController pushViewController: [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"YourViewController"] animated: YES];

最新更新