簡體   English   中英

如何從視圖的子視圖的視圖的自定義類中調用performSegueWithIdentifier?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM