【发布时间】:2016-06-08 21:00:42
【问题描述】:
我对在 UIViewController 和 UIView 之间拆分组件感到困惑。假设我用子视图制作了自定义 UIView:
@interface CustomView : UIView
@property(strong, nonatomic) UITextField *textField;
@property(strong, nonatomic) UIButton *button;
@property(strong, nonatomic) UIImageView *image;
@end
我想在控制器中实现的是在从视图中按下按钮后,我从 textField 中获取值并推送新的 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 之后 - ViewController 对 textField 一无所知...
【问题讨论】:
-
您是否在为这个自定义视图使用 Xib?
标签: ios objective-c uiview uiviewcontroller