简体   繁体   English

UILongPressGestureRecognizer如何将当前视图更改为另一个视图控制器?

[英]how can a UILongPressGestureRecognizer change the present view to another View Controller?

How do I programmatically change from my 1st view controller to my 2nd view controller, which in storyboard is linked to the 1st in storyboard? 如何以编程方式从第一个视图控制器更改为第二个视图控制器,该第二个控制器在情节提要中链接到情节提要中的第一个?

My iPad storyboard has a Tab Bar Controller as the "initial View Controller", which links through a "Relationship Seque view controllers" to a Navigation Controller, which links through a "root view" link, to View Controller A, which has a UIButton, which links through a 'Manual Seque push' to View Controller B. 我的iPad故事板上有一个标签栏控制器,作为“初始视图控制器”,它通过“关系Seque视图控制器”链接到导航控制器,后者通过“根视图”链接链接到具有UIButton的视图控制器A。 ,它通过“手动顺序推送”链接到View ControllerB。

Tab Bar Cntrl => Navigation Cntrlr ==(root view)==> View Cntrl A, UIButton ==(push)==> View Cntrl B 标签栏Cntrl =>导航Cntrlr ==(根视图)==>视图Cntrl A,UIButton ==(推)==>视图Cntrl B

So, when running, with View Controller A shown, pressing its UIButton causes the view to change to View Controller B. 因此,在运行时,在显示了View Controller A的情况下,按下其UIButton会使视图更改为View ControllerB。

There's another UIButton on a UITableView cell on View Controller A. When I press and hold this button, the delegate for UILongPressGestureRecognizer fires ok, and I need View Controller B to now be the view. 在视图控制器A的UITableView单元上还有另一个UIButton。当我按住此按钮时,UILongPressGestureRecognizer的委托会触发,并且我现在需要视图控制器B成为视图。

How then do I change from View Controller A to View Controller B? 然后如何从View Controller A更改为View Controller B? And with VC B open, how do I change back to VC A ? 在VC B打开的情况下,如何更改回VC A?

THE DELEGATE THAT RESPONDS TO PRESS-AND-HOLD............ - (void)schedule_long_press_delegate:(UILongPressGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { printf("Long press Ended ................. \\n"); 响应压住的委托.........-(void)schedule_long_press_delegate:(UILongPressGestureRecognizer *)recognizer {if(recognizer.state == UIGestureRecognizerStateEnded){printf(“ Long press Ended ................. \\ 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");
}        

} }

STORYBOARD SETTINGS: UITabBarController ... Storyboard ID is blank. 故事板设置:UITabBarController ...故事板ID为空白。 ..links to: UINavigationController ... Class=UINavigationController StoryboardID = "MANAGE_Storyboard_ID" ..links to: UIViewController ... Class=acc StoryboardID is blank (INITIAL VIEW) ..links to: UIViewController ... Class & StoryboardID = "SCHEDULE_UIViewController" (TARGET VIEW) ..链接至:UINavigationController ... Class = UINavigationController StoryboardID =“ MANAGE_Storyboard_ID” ..链接至:UIViewController ... Class = acc StoryboardID为空白(初始视图)..链接至:UIViewController ... Class&StoryboardID =“ SCHEDULE_UIViewController”(目标视图)

OUTPUT:.......... 输出:..........

mainStoryboard = 1f8b4900 mainStoryboard = 1f8b4900
MANAGE_UINavigationController = 1e5d45f0 MANAGE_UINavigationController = 1e5d45f0
schedule_UIViewController 2 = 1e5d4b20 schedule_UIViewController 2 = 1e5d4b20

In the delegate method for the long press gesture recognizer you can push view controller B from code like this: 在长按手势识别器的委托方法中,您可以从如下代码中推送视图控制器B:

ViewControllerB *viewControllerB = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ViewControllerB class])];
[self.navigationController pushViewController:viewControllerB animated:YES];

You can use a different identifier if you want; 如果需要,可以使用其他标识符。 using the class name is just my preference. 使用类名只是我的偏爱。

Changing back to view controller A will be handled for you by the navigation controller. 导航控制器将替您切换回视图控制器A。 The user will be presented with a back button in the upper left corner. 将在左上角为用户显示一个后退按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改当前视图控制器? - How to change the present view controller? 如何从另一个视图控制器呈现视图控制器 - How to present a view controller from another view controller UISplitViewController-如何临时显示另一个表视图控制器来代替小型主视图控制器? - UISplitViewController - How can I present another table view controller temporarily in place of the small master view controller? 查看控制器如何呈现自己? - How can view controller present it's self? 如何从另一个视图控制器更改文本? - How can I change the text from another view controller? 我如何使用swift在不是当前的视图控制器中显示从数据库中检索到的数据,而在ios中显示另一个 - how can i show retrieved data from database in not a present view controller but another one in ios with using swift 使用另一个视图控制器 swift 更改视图控制器 - Change View Controller with another view Controller swift 如何通过点击表格视图单元格内的标签来显示另一个视图控制器 - How to present another view controller by tapping on a label inside a tableview cell 如何在Swift中向另一个内部呈现视图控制器? - How do I present a view controller inside another in Swift? 如何不显示查看 Controller 模态 - How to not present View Controller Modally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM