[英]How to call performSegueWithIdentifier from within a custom class of a view that's a subview of view controller?
我有一个视图控制器,它有一个使用自定义类的子视图。 当我从视图控制器的上下文中执行performSegueWithIdentifier时,它工作正常,但是,如何在子子视图的上下文中调用performSegueWithIdentifier?
你不能从UIView
调用performSegue。 您可以使用协议,使viewController实现它并将其设置为自定义视图的委托。
CustomView.h
@protocol CustomViewDelegate
-(void)customView:(CustomView *)view performSegueWithIdentifier:(NSString *)identifier;
@end
@property (nonatomic, weak) id<CustomViewDelegate> delegate;
CustomView.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];
}
希望这可以帮助。 如果您有疑问,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.