[英]UIButton does not always fire
我正在扩展UITableViewController并以编程方式将uibutton添加到表页脚中,由于某种原因,uibutton仅在触摸顶部时才触发...好像某物掩盖了其余部分,我不明白它是什么我在viewForFooterInSection函数上有以下代码:
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)];
footerView.autoresizesSubviews = YES;
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
footerView.userInteractionEnabled = YES;
goButton = [UIButton buttonWithType:UIButtonTypeCustom];
[goButton addTarget:self action:@selector(getReport)forControlEvents:UIControlEventTouchUpInside];
[goButton setTitle:@"GO!" forState:UIControlStateNormal];
[goButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
goButton.frame = CGRectMake(50, 20, 220.0, 50.0);
UIImage *bg = [UIImage imageNamed: @"but_go.png"];
[goButton setBackgroundImage:bg forState:UIControlStateNormal];
[goButton setBackgroundColor:[UIColor clearColor]];
if (self.optimizations == nil || self.optimizations.count < 1){
goButton.enabled = NO ;
}
[footerView addSubview: goButton];
return footerView;
这是因为按钮的框架脱离了其父视图。 您需要增加footerView
的框架大小,以便按钮的整个部分都包含在footerView
。 您可以尝试将footerView
背景颜色设置为蓝色或红色,以查看实际的框架区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.