簡體   English   中英

刪除單元格時,UITableViewCells文本標簽將設置為單元格

[英]UITableViewCells text label gets set to a cell when the cell is deleted

我有一個UItableView我可以添加和刪除單元格。 我可以更改cell.textLabel.text屬性。 如果我將13添加到我的cell.textLabel.text ...

在此輸入圖像描述

如果我刪除TOP單元格,那個單元格的textLabel將設置為向上移動的單元格...

在此輸入圖像描述

我怎樣才能解決這個問題? 我希望能夠刪除一個單元格,讓它保持自己的textLabel 如果需要,這是我的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 ),以便數據源數組中的對象對應表格單元格的新索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM