我有一个 View Controller ,它有一个使用自定义类的 subview 。当我从 View Controller 的上下文中执行 performSegueWithIdentifier 时,它工作正常,但是,如何从子 subview 的上下文中调用 performSegueWithIdentifier?
最佳答案
您不能从 UIView
调用 performSegue .您可以使用协议(protocol),让 viewController 实现它并将其设置为自定义 View 的委托(delegate)。
自定义 View .h
@protocol CustomViewDelegate
-(void)customView:(CustomView *)view performSegueWithIdentifier:(NSString *)identifier;
@end
@property (nonatomic, weak) id<CustomViewDelegate> delegate;
自定义 View .m
// This is the event on which you would like to perform the segue
-(void)didClickButton {
[self.delegate customView:self performSegueWithIdentifier:@"mySegue"];
}
ViewController.m
-(void)viewDidLoad {
// All you other stuff...
// Set the delegate
self.customView.delegate = self;
}
-(void)customView:(CustomView *)view performSegueWithIdentifier:(NSString *)identifier {
[self performSegueWithIdentifier:identifier];
}
希望这可以帮助。如果您有任何问题,请告诉我
关于ios - 如何从 View Controller 的 subview 的自定义类中调用 performSegueWithIdentifier?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29437209/