我有四个选项卡。
在第一个标签中,我有一个按钮。当我单击此按钮时,我必须在第二个选项卡栏中从一个视图移动到另一个视图。
我当前使用的代码是(第二个选项卡在哪里shipVC
viewController
):
[shipVC.navigationController pushViewController:cartVC animated:NO];
所以基本上,当按下第一个选项卡中的按钮时viewController
,我想从第二个选项卡的“ X”视图移至“ Y”视图viewController
一种快速的方法是通过按下NSNotificationCenter
第一个选项卡中的按钮时发布通知viewController
。
viewController
的-viewDidLoad
方法:
viewController
button方法中:
您第二个标签的viewController
类别:
-(void)viewDidLoad {
[super viewDidLoad];
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doTheNavigation)
name:@"AnyNameYouWantForNotification"
object:nil];
}
-(void)doTheNavigation {
[self.navigationController pushViewController:cartVC animated:NO];
//WARNING: don't just push, put a check or else repeated click on the
//button in the 1st tab will push cartVC again and again.
//This will not only warrant a crash but look very ugly
}
第一个选项卡viewController
类中的Button方法:
-(IBAction)someBtnClick:(UIButton *)sender {
//...
//you can use this to post a notification from anywhere now
[[NSNotificationCenter defaultCenter] postNotificationName:@"AnyNameYouWantForNotification"
object:nil];
//...
}
someBtnClick
)将发布一个名称为AnyNameYouWantForNotification
AnyNameYouWantForNotification
。
doTheNavigation
)本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句