在View中对Button的触发事件或者didSelectRow都无法直接进行跳转到ViewController;
在这里就用代理来实现
1.首先在View的.h文件中
@protocol RecognitionResultViewDelegate <NSObject>
-(void)GoAskQuestionPushVC;
@optional
@end
@interface RecognitionResultView : UIView
@property(nonatomic,assign)id<RecognitionResultViewDelegate>delegate;
@end
2.在View.m中的触发方法里
[self.delegate GoAskQuestionPushVC];、
3.在VIewController中
1️⃣@interface RecognitionResultViewController ()<RecognitionResultViewDelegate>
2️⃣ _recognitionV.delegate = self;
3️⃣
- (void)GoAskQuestionPushVC {
AskQuestionViewController *askVC = [[AskQuestionViewController alloc]init];
[self.navigationController pushViewController:askVC animated:YES];
}
就这么简单就可以实现在View中跳转到ViewControlelr的功能了
本文介绍了一种在iOS开发中,利用代理模式从自定义UIView跳转到UIViewController的方法。通过在UIView中定义代理协议,并在UIViewController中实现该协议,可以实现在UIView内的操作触发UIViewController的跳转。具体步骤包括:定义代理协议、设置代理属性、实现代理方法以及触发代理方法。
5565

被折叠的 条评论
为什么被折叠?



