Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIViewController不检测点击/触摸事件_Ios_Objective C_Uiview_Uiviewcontroller - Fatal编程技术网

Ios UIViewController不检测点击/触摸事件

Ios UIViewController不检测点击/触摸事件,ios,objective-c,uiview,uiviewcontroller,Ios,Objective C,Uiview,Uiviewcontroller,我正在以编程方式创建UIViewController。在它的viewDidLoad中,我正在创建自定义UIView组件的实例,该组件有一堆按钮和文本字段。我将此视图设置为viewControllers视图 但当我选择任何UIButton时,它不会触发任何事件,或者点击UITextField内部也不会打开键盘 - (void)viewDidLoad { [super viewDidLoad]; SomeView *sv = [[SomeView alloc] initWithFra

我正在以编程方式创建UIViewController。在它的viewDidLoad中,我正在创建自定义UIView组件的实例,该组件有一堆按钮和文本字段。我将此视图设置为viewControllers视图

但当我选择任何UIButton时,它不会触发任何事件,或者点击UITextField内部也不会打开键盘

- (void)viewDidLoad
{
    [super viewDidLoad];
    SomeView *sv = [[SomeView alloc] initWithFrame:self.view.bounds];
    self.view.userInteractionEnabled = YES;
    self.view = sv;
    //[self.view addSubView:sv];
    self.title = @"Something";
}
这段代码有什么问题吗?即使添加subivew也不起作用。 我在sv中添加了TapSignature,它被检测到了,但在视图中没有选择任何其他内容


我尝试将按钮/文本字段直接添加到viewcontrollers视图中。然后它可以工作,但不能通过customview组件

尝试保持对视图的强引用,它可能会被解除分配

@interface YOURCLASS ()
@property (nonatomic, strong) SomeView *sv;
@end
然后返回,尝试将其添加为子视图。看看这是否有效

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.sv = [[SomeView alloc] initWithFrame:self.view.bounds];
    self.view.userInteractionEnabled = YES;
    [self.view addSubView:self.sv];
    self.title = @"Something";
}

所以你看到了按钮,但点击它们什么都没有?是的,我看到了UIButtons,UITextField,但我不能选择它们。如果我直接将它们添加到self.view而不是customview中,它会起作用。检查如果这样做会发生什么:self.view.cliptobunds=YES,self.sv.cliptobunds=YES;可能视图的大小不合适。