我很困惑与UIViewController和UIView之间分裂组件。比方说,我做了自定义的UIView与子视图:自定义UIView链接到UIViewController - 如何处理按钮动作
@interface CustomView : UIView
@property(strong, nonatomic) UITextField *textField;
@property(strong, nonatomic) UIButton *button;
@property(strong, nonatomic) UIImageView *image;
@end
我想什么是从视图推按钮我是从文本框取价值,推动新navigationController后实现控制器。但我不知道如何正确地做到这一点。我现在正在尝试的是这样的:
@implementation CustomViewController
- (void)viewDidLoad {
[super viewDidLoad];
CustomView *customView = [[CustomView alloc] init];
[customView.searchButton addTarget:self action:@selector(didPushSearchButton) forControlEvents:UIControlEventTouchUpInside];
self.view = customView;
}
- (void)didPushSearchButton {
//pushing new viewController, but how can i get value from text field here?
}
@end
我可以说CustomViewController,它的视图是类型CustomView?我可以获得textField的值,因为我可以输入self.view.textField。现在打字self.view之后 - 如果你不使用故事板或文件的.xib视图控制器不知道什么文本框...
您是否在这个自定义视图中使用Xib? – Jaimish
不,全部用代码 – magiczek91