UIButton并不总是开火

时间:2010-11-09 16:44:56

标签: iphone objective-c cocoa-touch uibutton

我正在扩展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;

1 个答案:

答案 0 :(得分:3)

这是因为按钮的框架从其父视图中掉出来了。您需要增加footerView的框架大小,以便按钮的整个部分包含在footerView中。您可以尝试将footerView背景颜色设置为蓝色或红色以查看实际的帧区域。