我只是想从UIButton导航到我的第三个ViewController,但我不知道如何调用它。我知道如何回调和根ViewController而不是特定的“IBThirdViewController”。不确定我是否可以做这样的事情并按名称命名
- (IBAction)tourButton:(id)sender {
[self.navigationController pushViewController:IBTHirdViewController animated:YES];
}
答案 0 :(得分:0)
如果弹出视图上有按钮,则应创建块或委托。所以假设controllerA弹出了controllerB。据我所知,你的controllerB是一个弹出窗口,它包含处理程序- tourButton
的按钮。
在这种情况下,您应该将委托添加到您的controllerB。所以我不确定你的类和结构的名称,但是打开弹出控制器(在我的例子中是controllerB)并在@interface之前添加以下行:
@protocol PopUpControllerDelegate <NSObject>
- (void)tourButtonTouched;
@end
在controllerB中:
@interface YOUR_POPUP_CONTROLLER_CLASSNAME_OR_CLASS_B : UIViewController
@property (nonatomic, assign) id <PopUpControllerDelegate> delegate;
所以在controllerA中你应该有controllerB实例。在内存中分配此实例后,将委托给对象控制器
controllerB.delegate = self;
此外,您还需要在controllerA类中实现委托回调实现:
- (void)tourButtonTouched
{
// Here will be you code that push 3rd controller. Be sure that self (current) controller has navigation parent controller. Because in another push method will no work.
[self.navigationController pushViewController:IBTHirdViewController animated:YES];
// Use present if there is no navigation controller: [self presentViewController:IBTHirdViewController animated:YES];
}