Я хочу динамически добавить UIB-кнопку в ячейку таблицы - см. Требования ниже.
Когда пользователь выбирает ячейку, я просто настраиваю высоту этой ячейки таблицы в
-(void) tableView:(UITableView*) tableView didSelectRowAtIndexPath:(UIIndexPath*) indexPath {
selIndPath = [indexPath retain];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
Вышеуказанный метод заставляет tableView регулировать высоту выбранной строки. Но когда я добавил UIButton вышеописанным способом, кнопка не видна.
Меня не интересует [self.tableView reloadData];
Любая помощь с благодарностью.
***** EDITED *******
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (selIndPath && selIndPath == indexPath) {
//UITableViewCell* cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
// UIButton* btn = (UIButton*)[[cell contentView] viewWithTag:1234];
// btn.frame = CGRectMake(40, 60, 60, 24);
// [cell setNeedsDisplay];
return 90;
}
return 64;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[[cell contentView] setBackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]];
}
// THIS LINES OF CODE WORKS ONLY ON reloadData
if (selIndPath && selIndPath == indexPath) {
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(40, 60, 60, 24);
btn.tag = 1234;
[btn setTitle:@"Hi" forState:UIControlStateNormal];
[cell.contentView addSubview:btn];
}
// Configure the cell.
cell.textLabel.text = @"Loading..";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selIndPath = [indexPath retain];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
//[self.tableView reloadData];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}