【发布时间】:2012-10-18 11:08:58
【问题描述】:
我正在尝试在 UITableView 中选择一行时添加一个按钮,并在第二次点击该行时将其删除,我不想要自定义 UITableViewCell。
任何建议或示例代码将不胜感激。
我尝试过的代码: 在 cellForRowAtIndexPath 方法中
if(cell.selected == YES){
UITextField* numOfBottles =[[UITextField alloc] initWithFrame:CGRectMake(240,9.0f,50, 25)];
numOfBottles.tag = indexPath.row;
[numOfBottles setBorderStyle:UITextBorderStyleNone];
[numOfBottles setBackgroundColor:[UIColor clearColor]];
[numOfBottles setTextColor:[UIColor whiteColor]];
[numOfBottles setTextAlignment:UITextAlignmentLeft];
[numOfBottles setBackground:[UIImage imageNamed:@"blue_dropdown_normal.png"]];
[numOfBottles setFont:[UIFont systemFontOfSize:16.0f]];
[numOfBottles setDelegate:self];
NSString* quantity = [[NSString alloc] initWithString:[subtotalObj.qtyArray objectAtIndex:(indexPath.row - 1)]];
[numOfBottles setText:quantity];
[numOfBottles setTextAlignment:UITextAlignmentCenter];
[numOfBottles setBackgroundColor:[UIColor whiteColor]];
numOfBottles.keyboardType = UIKeyboardTypeDefault;
// numOfBottles.tag = indexPath.row;
[cell.contentView addSubview:numOfBottles];
[numOfBottles release];
}
在 didSelectRowAtIndexPath 方法中
[tableView reloadData];
但按钮(带有背景图像的文本字段)仍然没有呈现。
【问题讨论】:
标签: objective-c ios ios5 uitableview