如何以编程方式从第一个视图控制器更改为第二个视图控制器,故事板中的第一个视图控制器链接到故事板中的第一个?
我的iPad故事板有一个标签栏控制器作为“初始视图控制器”, 通过“关系Seque视图控制器”链接 通过“根视图”链接链接到视图控制器A的导航控制器,视图控制器A具有UIButton,通过“手动推送推送”链接到视图控制器B.
Tab Bar Cntrl =>导航Cntrlr ==(根视图)==>查看Cntrl A,UIButton ==(推)==>查看Cntrl B
因此,在运行时,如果显示View Controller A,按下其UIButton会导致视图更改为View Controller B.
View Controller A上的UITableView单元上还有另一个UIButton。当我按住此按钮时,UILongPressGestureRecognizer的委托会激活,我现在需要View Controller B作为视图。
如何从View Controller A更改为View Controller B? 在VC B打开的情况下,如何更改回VC A?
响应压力和保持的代表............ - (void)schedule_long_press_delegate:(UILongPressGestureRecognizer *)识别器 { if(recognizer.state == UIGestureRecognizerStateEnded){ printf(“长按结束................. \ n”);
// Get storyboard:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
bundle: nil];
printf("mainStoryboard = %x \n", (int)mainStoryboard ); // !!! ax
// Get nav controller for MANAGE view:
UINavigationController *MANAGE_UINavigationController = (UINavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"MANAGE_Storyboard_ID"];
printf("MANAGE_UINavigationController = %x \n", (int)MANAGE_UINavigationController ); // !!! ax
// Get MANAGE view's view controller:
SCHEDULE_UIViewController *schedule_UIViewController = [self.storyboard instantiateViewControllerWithIdentifier:
NSStringFromClass([SCHEDULE_UIViewController class])];
printf("schedule_UIViewController = %x \n", (int)schedule_UIViewController ); // !!! ax
// Change screen to MANAGE view:
[MANAGE_UINavigationController pushViewController: schedule_UIViewController animated:YES];
}
else {
printf("Long press detected ..................... \n");
}
}
故事板设置: UITabBarController ...故事板ID为空。 ..链接到: UINavigationController ... Class = UINavigationController StoryboardID =“MANAGE_Storyboard_ID” ..链接到: UIViewController ... Class = acc StoryboardID为空(INITIAL VIEW) ..链接到: UIViewController ... Class& StoryboardID =“SCHEDULE_UIViewController”(TARGET VIEW)
输出:..........
mainStoryboard = 1f8b4900
MANAGE_UINavigationController = 1e5d45f0
schedule_UIViewController 2 = 1e5d4b20
答案 0 :(得分:0)
在长按手势识别器的委托方法中,您可以从以下代码中推送视图控制器B:
ViewControllerB *viewControllerB = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ViewControllerB class])];
[self.navigationController pushViewController:viewControllerB animated:YES];
如果需要,您可以使用其他标识符;使用班级名称只是我的偏好。
导航控制器将为您处理更改回视图控制器A.用户将在左上角看到一个后退按钮。