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を並べて配置したいだけで、ボタンのサイズは横向きまたは縦向きのセルのサイズに収まる必要があります。その方法を知っていますか?ありがとう。