Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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 UIView子视图按钮未激活_Ios_Uiview_Addsubview - Fatal编程技术网

Ios UIView子视图按钮未激活

Ios UIView子视图按钮未激活,ios,uiview,addsubview,Ios,Uiview,Addsubview,我想在UIImageView中添加按钮。添加的按钮未激活 UIImageView *iview = [[UIImageView alloc] initWithImage:image]; iview.frame = [[UIScreen mainScreen] applicationFrame]; iview.contentMode = UIViewContentModeTopLeft; UIButton *bview1 = [UIButton buttonWithType:UIButtonTy

我想在UIImageView中添加按钮。添加的按钮未激活

UIImageView *iview = [[UIImageView alloc] initWithImage:image];
iview.frame = [[UIScreen mainScreen] applicationFrame];
iview.contentMode = UIViewContentModeTopLeft;

UIButton *bview1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
bview1.frame = CGRectMake(0, 0, 200, 60);
bview1.center = CGPointMake(100, 100);
[bview1 addTarget:self action:@selector(buttonPress1:) forControlEvents:UIControlEventTouchUpInside];
[bview1 setTitle:@"Image Picker1" forState:UIControlStateNormal];

[iview addSubview:bview1];

[self.view addSubview:iview];
处理程序:

- (void)buttonPress1:(id)sender
{
    NSLog(@"1");
}
怎么了?

您是否尝试过:

iview.userInteractionEnabled = YES;

UIImageView的默认userInteractionEnabled==否,因此答案是正确的。没问题,感谢您接受答案,我很高兴它能工作!