Ios 如何从';视图控制器的子视图是什么?

Ios 如何从';视图控制器的子视图是什么?,ios,objective-c,xcode6,Ios,Objective C,Xcode6,我有一个视图控制器,它有一个使用自定义类的子视图。当我从视图控制器的上下文中执行PerformsgueWithIdentifier时,它可以正常工作,但是,如何从子视图的上下文中调用PerformsgueWithIdentifier?您不能从UIView调用PerformsgueWithIdentifier。您可以使用协议,使viewController实现它,并将其设置为自定义视图的委托 CustomView.h @protocol CustomViewDelegate -(void)cus

我有一个视图控制器,它有一个使用自定义类的子视图。当我从视图控制器的上下文中执行PerformsgueWithIdentifier时,它可以正常工作,但是,如何从子视图的上下文中调用PerformsgueWithIdentifier?

您不能从
UIView
调用PerformsgueWithIdentifier。您可以使用协议,使viewController实现它,并将其设置为自定义视图的委托

CustomView.h

@protocol CustomViewDelegate

-(void)customView:(CustomView *)view performSegueWithIdentifier:(NSString *)identifier;

@end

@property (nonatomic, weak) id<CustomViewDelegate> delegate;
ViewController.m

// This is the event on which you would like to perform the segue
-(void)didClickButton {
     [self.delegate customView:self performSegueWithIdentifier:@"mySegue"];
}
-(void)viewDidLoad {
    // All you other stuff...

    // Set the delegate
    self.customView.delegate = self;
}

-(void)customView:(CustomView *)view performSegueWithIdentifier:(NSString *)identifier {
    [self performSegueWithIdentifier:identifier];
}

希望这有帮助。如果您有问题,请告诉我

我们可以了解更多详细信息吗?代码?您将属性id委托放在哪里?在您的自定义视图中,当事件发生时,您希望执行segue。