Iphone UITableViewCells文本标签在删除单元格时设置为单元格
我有一个UItableView,可以添加和删除单元格。我可以更改Iphone UITableViewCells文本标签在删除单元格时设置为单元格,iphone,ios,cocoa-touch,uitableview,Iphone,Ios,Cocoa Touch,Uitableview,我有一个UItableView,可以添加和删除单元格。我可以更改单元格.textLabel.text属性。如果我将13添加到我的单元格.textlab.text 如果我删除顶部的单元格,则该单元格的textlab将设置为表中向上移动的单元格 我怎样才能解决这个问题?我希望能够删除单元格并使其保留自己的textlab。以下是我的cellForRow方法(如果需要): - (UITableViewCell *)tableView:(UITableView *)tableView cell
单元格.textLabel.text
属性。如果我将13添加到我的单元格.textlab.text
如果我删除顶部的单元格,则该单元格的textlab
将设置为表中向上移动的单元格
我怎样才能解决这个问题?我希望能够删除单元格并使其保留自己的textlab
。以下是我的cellForRow
方法(如果需要):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
addBtn = [[UIButton alloc]init];
addBtn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[addBtn setFrame:CGRectMake(220,10,25,55)];
[addBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
[addBtn setTitle:@"+" forState:UIControlStateNormal];
[addBtn setEnabled:YES];
[cell addSubview:addBtn];
subBtn = [[UIButton alloc]init];
subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[subBtn setFrame:CGRectMake(260,10,25,55)];
[subBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
[subBtn setTitle:@"-" forState:UIControlStateNormal];
[subBtn setEnabled:YES];
[cell addSubview:subBtn];
}
//cellText.hidden=!self.editing;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.imageView.image = [imageArray objectAtIndex:indexPath.row];
cell.tag = indexPath.row; // Important for identifying the cell easily later
cell.textLabel.text = [self.number objectAtIndex:indexPath.row];
return cell;
}
提前感谢您的帮助 删除单元格时,您的
UITableView
会重新绘制其中的所有单元格。删除单元格时,还需要从数据源中删除相应的对象(在您的情况下,是数组self.number
),以便数据源数组中的对象与表格单元格的新索引相对应