简体   繁体   English

如何通过使用滚动操作从子viewcontroller继承父viewcontroller?

[英]How to come parent viewcontroller from child viewcontroller by using scrolling action?

I have two UIViewController named as ViewControllerA and ViewControllerB . 我有两个名为ViewControllerA and ViewControllerB UIViewController。 ViewControllerA is the parent class and ViewControllerB is a child class, it is view by [self.navigationController pushViewController:viewControllerB animated:YES]; ViewControllerA是父类,ViewControllerB是子类,通过[self.navigationController pushViewController:viewControllerB animated:YES];查看[self.navigationController pushViewController:viewControllerB animated:YES]; from ViewControllerA class. 从ViewControllerA类。 In ViewControllerB class i hidden the NavigationBar. 在ViewControllerB类中,我隐藏了NavigationBar。 In button action i coded to come ViewControllerA from ViewControllerB [self.navigationController popViewControllerAnimated:YES]; 在按钮操作中,我编码为从ViewControllerB到ViewControllerA [self.navigationController popViewControllerAnimated:YES]; . Now, i want to come ViewControllerA from ViewControllerB using swapping action(Scroll to previous screen) rather than using UIButton. 现在,我想使用交换操作(滚动到上一个屏幕)而不是使用UIButton从ViewControllerB中获取ViewControllerA。 How can i do this? 我怎样才能做到这一点? Can anyone please provide me any suggestion or ideas? 谁能给我任何建议或想法? Thanks in advance. 提前致谢。

You can try to use UISwipeGestureRecognizer on your child view with handler method that does the [self.navigationController popViewControllerAnimated:YES]; 您可以尝试使用具有[self.navigationController popViewControllerAnimated:YES];处理程序方法在子视图上使用UISwipeGestureRecognizer [self.navigationController popViewControllerAnimated:YES]; .

Use this in child controller 在子控制器中使用此

- (void)viewDidLoad 
{    
    UISwipeGestureRecognizer  *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release]; 
    [super viewDidLoad];
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
 {
    [self.navigationController popViewControllerAnimated:YES];
    NSLog(@"Swipe received.");
 }

Use Direction as you want.. 根据需要使用“方向”。

Happy Coding... 快乐编码...

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

相关问题 从子viewcontroller设置父viewcontroller类的属性值? - Setting property value of parent viewcontroller class from child viewcontroller? 如何从子viewController中的UITableView更新父控制器中的UIScrollView的contentSize - How to update the contentSize of UIScrollView in a parent controller from a UITableView in Child viewController 应该从父 ViewController 还是子 ViewController 调用 popViewController? - Should popViewController be called from the parent or child ViewController? 在子视图控制器中重用父视图控制器故事板文件 - Reuse parent ViewController storyboard file in Child ViewController 从UITableViewCell到ViewController的按钮操作 - Button Action from UITableViewCell to ViewController 防止“父级”视图控制器旋转 - Prevent 'parent' viewcontroller from rotating 从父ViewController获取字符串? - Get String From Parent ViewController? 如何从第三viewController回到第一viewcontroller? - how to back from third viewController to first viewcontroller? 如何从另一个viewcontroller的图标操作中加载主ViewController的视图? - How can i Load my main ViewController's view, from another viewcontroller's icon action? iPhone:如何从viewcontroller获取customcell的按钮动作? - iPhone:How to get the button action of a customcell from the viewcontroller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM