我有一個UITableViewCell。我可以從單元的textLabel
加減1
,我也可以刪除單元格。這是我的問題,可以說我給textLabel
的值加5。而這個單元格位於0 indexPath(表格中的第一個單元格)。當我刪除這個單元格並且現在表格中不再有任何單元格時,我添加一個新單元格,並且這個新單元格自動獲得與剛被刪除的單元格相同的值。所以這個新單元格的值將爲5
,我希望單元格的值爲1,就像每個單元格添加時一樣。只有當一個單元格被刪除並且一個新的單元格被添加到完全相同的indexPath時,纔會發生這種情況。所以我的問題是:我是否必須刪除這個單元格「內存」或「數據」才能解決這個問題?感謝一幫幫忙!刪除UITableViewCell和該單元格的所有數據
的cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
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];
//cell.textLabel.text = @"1";
}
//cellText.hidden=!self.editing;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.imageView.image = [imageArray objectAtIndex:indexPath.row];
cell.textLabel.text = [number objectAtIndex:indexPath.row];
return cell;
}
你可以發佈'cellForRowAtIndexPath:'方法的代碼嗎?這聽起來像是你在'dequeueReusableCellWithIdentifier:' – jonkroll 2012-01-17 05:22:09
在你的UITableView上發佈了一些代碼,其中textLabel的值來自哪裏,你沒有正確配置textLabel的值?數組?或者其他什麼,也可能是因爲這個單元正在被重用。發佈你的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)索引路徑如果可能 – 2012-01-17 05:23:38
@jonkroll肯定我會發布它吧! – iProRage 2012-01-18 00:07:46