I am adding UITableView and UIButton in UIScrollView. button is placed below tableview.
Well, when i select any row from table it add a button on that row and every thing is ok till now, but when i click that row second time it remove button added on it but the problem is that along with removing that button it also scroll my table up and button bellow the table reside on its place ie. it leaves gap between table and button.
my table is reloaded every time when a row is clicked.
code for add UIButtonbelow the UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
mainTable.frame = CGRectMake(mainTable.frame.origin.x, mainTable.frame.origin.y,
mainTable.frame.size.width,
([menuItemsArray count] * 60) + 380);
[scrollView setContentSize:CGSizeMake(320,([menuItemsArray count] * 60) + 80 + 350)];
reserverBtnBottom = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[reserverBtnBottom setFrame:CGRectMake(20.0f,mainTable.frame.size.height,280, 40)];
[reserverBtnBottom addTarget:self action:@selector(reserveBtnAction) forControlEvents:UIControlEventTouchUpInside];
[reserverBtnBottom setBackgroundImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
[reserverBtnBottom setAlpha:1];
[reserverBtnBottom setTitle:@"Reserve this table" forState:UIControlStateNormal];
[reserverBtnBottom setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[scrollView addSubview:reserverBtnBottom];
rest thing goes here
}
What am i missing?
Thanks in advance.
After long time i resolve my problem. put this code in
viewWillAppearinsteadheightForRowAtIndexPath–and move my reserveBtnBottom to footer of UITableView.
Thanks to A-Live for his great help.