在 uiviewcontroller 中导航 iOS
Navigate in uiviewcontroller iOS
我在导航到特定 UIViewController
时遇到内存管理问题
示例:
我有 3 个 UIViewController
并使用 Storyboard modal segue,我留在第一个,我需要直接转到第 3 个
我使用这段代码工作正常,但是当我需要 return 到 1 时,如果我重复这段代码。我收到内存警告并稍后崩溃。
这是我的代码:
转到视图 3 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:@"Three"];
[self presentViewController:viewTree animated:YES completion:nil];
转到视图 1 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewOne = [storybord instantiateViewControllerWithIdentifier:@"One"];
[self presentViewController:viewOne animated:YES completion:nil];
您必须不断地相互呈现每个视图控制器,这会引发内存警告问题。要显示 ViewControllerThree
,请在 ViewControllerOne
中使用以下代码
@implementation ViewControllerOne
- (IBAction) goto3 {
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:@"Three"];
// Brings you to the third view controller.
[self presentViewController:viewTree animated:YES completion:nil];
}
@end
然后返回 ViewControllerOne
在 ViewControllerThree
中执行此代码
@implementation ViewControllerThree
-(IBAction) backTo1 {
// Dismisses the third view and brings you back to the first view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}
我在导航到特定 UIViewController
示例:
我有 3 个 UIViewController
并使用 Storyboard modal segue,我留在第一个,我需要直接转到第 3 个
我使用这段代码工作正常,但是当我需要 return 到 1 时,如果我重复这段代码。我收到内存警告并稍后崩溃。
这是我的代码:
转到视图 3 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:@"Three"];
[self presentViewController:viewTree animated:YES completion:nil];
转到视图 1 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewOne = [storybord instantiateViewControllerWithIdentifier:@"One"];
[self presentViewController:viewOne animated:YES completion:nil];
您必须不断地相互呈现每个视图控制器,这会引发内存警告问题。要显示 ViewControllerThree
,请在 ViewControllerOne
@implementation ViewControllerOne
- (IBAction) goto3 {
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:@"Three"];
// Brings you to the third view controller.
[self presentViewController:viewTree animated:YES completion:nil];
}
@end
然后返回 ViewControllerOne
在 ViewControllerThree
@implementation ViewControllerThree
-(IBAction) backTo1 {
// Dismisses the third view and brings you back to the first view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}