Reputation: 1371
after some discussion on this topic I'm attemting to implement 2 buttons on the footerview on a UItableView. To create the buttons, I declare them on the declaration .h file, synthesized on the implementation .m file and then, I created them by code, like this:
- (UIButton *)resetButton{
if (resetButton == nil)
{
resetButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
resetButton.frame = CGRectMake(20.0, 40 , 95.0, 37.0);
[resetButton setTitle:@"Reset" forState:UIControlStateNormal];
resetButton.backgroundColor = [UIColor clearColor];
[resetButton addTarget:self action:@selector(resetAction:) forControlEvents:UIControlEventTouchDown];
resetButton.tag = 1;
}
return resetButton;
}
and then, I implemented this code into the UITableView delegate method:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 100.0)];
[customView addSubview:self.resetButton];
[customView addSubview:self.calculateButton];
return [customView autorelease];
}
by doing so, the buttons appear on the screen however, when I tap them, nothing happens (I implemented a AlertView on the actions to check if they work.
any help here?
Thanks!
EDIT: the actions linked to the button:
-(IBAction)resetAction:(id)sender {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Reset"
message:@"You just pressed the Reset button"
delegate:self
cancelButtonTitle:@"Acknowledged"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Upvotes: 0
Views: 4512
Reputation: 585
I think what you are missing is - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
.
Without this the custom footer will be height 0. The reason you can still see the button is because clipsToBounds
is NO
by default for the custom view.
Upvotes: 5