UITableViewCell 中的按钮有问题。请帮我。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
switch (indexPath.section) {
case 0:
break;
case 2:{
cell.accessoryType = UITableViewCellAccessoryNone;
// Make backgroung invisible
[self cellBackground:cell];
// Make the save button
[self saveButton:cell];
[self showButton:cell];
}
break;
}
}
return cell;
}
- (void)saveButton:(UITableViewCell *)cell {
UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[saveButton setTitle:@"Save" forState:UIControlStateNormal];
saveButton.frame = CGRectMake(45, 0, 300, 45);
saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
saveButton.contentEdgeInsets = UIEdgeInsetsMake(0,10,0,0);
[cell addSubview:saveButton];
}
- (void)showButton:(UITableViewCell *)cell{
UIButton *showButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[showButton setTitle:@"Show" forState:UIControlStateNormal];
showButton.frame = CGRectMake(45, 0, 300, 45);
showButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
showButton.contentEdgeInsets = UIEdgeInsetsMake(0,10,0,0);
[cell addSubview:showButton];
}
我只想在 indexPath.section = 2 中并排设置 saveButton 和 showButton,并且按钮的大小应该适合横向或纵向单元格的大小。你知道怎么做吗?谢谢。