Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableViewCells文本标签在删除单元格时设置为单元格_Iphone_Ios_Cocoa Touch_Uitableview - Fatal编程技术网

Iphone UITableViewCells文本标签在删除单元格时设置为单元格

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

我有一个UItableView,可以添加和删除单元格。我可以更改
单元格.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
),以便数据源数组中的对象与表格单元格的新索引相对应