我有两个 View Controller UserListView
和 UserProfileView
!
在 UserListView
View Controller 中,我有一个用于切换到 UserProfileView
的按钮,这是代码。
UserListView.m - 单击操作
- (IBAction)SettingClick:(id)sender
{
UserList *UserProfile = [self.storyboard instantiateViewControllerWithIdentifier:@"UserProfileView"];
[self presentViewController:UserProfile animated:YES completion:nil];
}
代码工作正常,当用户切换到配置文件 (UserProfileView) 时有一个关闭按钮返回到 UserListView
,这里是代码。
UserProfileView.m - 关闭点击 Action
- (IBAction)CloseClick:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
UserProfile *UseList = [self.storyboard instantiateViewControllerWithIdentifier:@"UserListView"];
[self presentViewController:UseList animated:YES completion:nil];
}
在这段代码中,我将使用 [self dismissViewControllerAnimated:YES completion:nil];
关闭 UserProfileView
View Controller 以降低 ram 使用率并且它可以工作。
但是在我关闭 UserProfileView
之后我想再次打开这个 View Controller 但它不起作用,UserProfileView
不再显示了??
我正在使用 xcode 5 并为 ios 7 构建应用程序,请帮忙。
感谢您的宝贵时间。
最佳答案
如果我理解正确,当您调用 SettingClick:
时,您的应用会显示一个 UserList
。因此,当您关闭显示在它上面的 View Controller 时,您应该返回到 UserList
而无需再次显示它。所以你可以试试:
- (IBAction)CloseClick:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
这将有效,除非您最初也提供了 UserList
。在这种情况下,UserList
将被顶层 Controller 关闭。在这种情况下,您可以在关闭 UserProfile
之后延迟第二次显示 UserList
,它应该可以工作。
在后一种情况下,我建议您使用导航 Controller ,而不是像您正在做的那样简单地展示您的 Controller 。如您所见,这并不是很简单,您会陷入任何困境。当您一次只显示一个 Controller 时,显示 Controller 工作正常。另一方面,如果您实例化一个 UINavigationController
,这将为您处理 Controller 的层次结构。
关于ios - 切换两个 View Controller ,后退功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24569361/