开发者

UIButton does not always fire

开发者 https://www.devze.com 2023-01-24 00:38 出处:网络
i\'m extending UITableViewController and have a uibutton added programtticly to the table footer , for some reason the uibutton fire only when touch in the top part ... as if someting is masking the r

i'm extending UITableViewController and have a uibutton added programtticly to the table footer , for some reason the uibutton fire only when touch in the top part ... as if someting is masking the rest of it and i can't understand what it is i have the following code at viewForFooterInSection function:

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:UIControlEventTouchUpIns开发者_运维技巧ide];
[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;


It's because the button's frame fell out of its parent view. You need to increase your footerView's frame size so the whole part of the button contains in the footerView. You can try to set footerView background color to blue or red to see the actual frame area.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号