我的 viewDidLoad 方法中有以下代码。这是一个带有滚动视图和页面控制器的 uiviewcontroller。
我有以下代码,它从数组创建视图在第 3 页上放置了一个按钮:
for (int i = 0; i < imageNames.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
UIImageView *myImageView =[[UIImageView alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)];
myImageView.image=[UIImage imageNamed:[imageNames objectAtIndex:i]];
[subview addSubview: myImageView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[button addTarget:self
action:@selector(doSomething:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
if(i == 1){
[myImageView addSubview:button];
}
[self.scrollView addSubview:subview];
}
我有一个 ibaction 将关闭这个视图,因为它是模态视图: -(IBAction)doSomething:(id)sender{ [self dismissModalViewControllerAnimated:YES]; }
问题是这个按钮没有响应。它甚至不会在触摸时突出显示,更不用说调用 doSomething 方法了。
我究竟做错了什么?