我有一个视图控制器,它有一个使用自定义类的子视图。当我从视图控制器的上下文中执行performSegueWithIdentifier时,它工作正常,但是,如何在子子视图的上下文中调用performSegueWithIdentifier?
答案 0 :(得分:3)
您无法从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];
}
希望这会有所帮助。如果您有疑问,请告诉我