Iphone UiTableView错误,添加的单元格不需要插入文本

Iphone UiTableView错误,添加的单元格不需要插入文本,iphone,uitableview,Iphone,Uitableview,嘿,伙计们,我有一个可以添加和删除单元格的表视图。但是,当我删除应用程序附带的唯一单元格时,我尝试添加一个带有“Meghan Way”文本的新单元格,该文本会自动将其自身更改为原始单元格文本“House 1”,这是我的代码 - (IBAction)saveButton:(id)sender { FacePlatesViewController * viewController = (FacePlatesViewController *)self.parentViewController;

嘿,伙计们,我有一个可以添加和删除单元格的表视图。但是,当我删除应用程序附带的唯一单元格时,我尝试添加一个带有“Meghan Way”文本的新单元格,该文本会自动将其自身更改为原始单元格文本“House 1”,这是我的代码

- (IBAction)saveButton:(id)sender {
FacePlatesViewController * viewController = (FacePlatesViewController   
*)self.parentViewController;

[viewController addObject:[NSMutableDictionary dictionaryWithObject:text.text    
forKey:@"name"]]; 

[self dismissModalViewControllerAnimated:YES];
}

- (IBAction)cancel:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   
(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero   
reuseIdentifier:CellIdentifier] autorelease];
    cell.textLabel.text = [[cells objectAtIndex:indexPath.row] valueForKey:@"name"];
UIImage * myimage = [UIImage imageNamed: @"check.png"];
image = [[UIImageView alloc]initWithImage:myimage];



tableView.backgroundColor = [UIColor clearColor];


    self.myTableView = tableView;


}
return cell;

}

这是保存按钮!非常感谢您的帮助:D谢谢

您是否将这些单元格的文本标签存储在任何类型的数组或字典中,并使用标准的“CellForRowatineXpath”将其加载到其中?如果是,则需要删除该数据源中的字典/数组条目,以防止其再次被使用


如果没有看到更多的代码,我无法确定……但这听起来像是一个细胞回收问题。我可能错了……但我需要查看更多信息。

您的代码非常混乱。我在下面对其进行了改进并添加了评论:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   
(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero   
    reuseIdentifier:CellIdentifier] autorelease];
    }  //The if block should end here. You should set the cell's label irrespective whether the cell was nil. This is the cause of the issue you are facing.

    cell.textLabel.text = [[cells objectAtIndex:indexPath.row] valueForKey:@"name"];

    //You are doing nothing with the UIImage
    //UIImage * myimage = [UIImage imageNamed: @"check.png"];
    //image = [[UIImageView alloc]initWithImage:myimage];


    //You should be setting the background color just once, in ViewDidLoad, not here.
    //tableView.backgroundColor = [UIColor clearColor];

    //I don't see why this is required
    //self.myTableView = tableView;

    return cell;

}

我们需要FacePlatesViewController的代码来帮助您解决这个问题。我真的怀疑这是UITableView的一个bug,正如标题所说。是的,我是用plist做的。。我会用cellForRow更新这个问题。谢谢你的帮助:哦,问题不在于删除文本中的单元格。该应用程序以1个名为“House 1”的单元格开始,当用户删除该单元格并添加新单元格时,它们将被带到另一个页面以键入新单元格的文本。当他们点击“保存”按钮时,文本不是他们输入的,它仍然是“House 1”嘿,抱歉打扰你,但是你的代码很有魅力,非常感谢,但是错误现在出现在另一个地方:添加单元格后,文本是好的,但是当我切换页面然后返回时,单元格返回到house 1文本。你知道这是为什么吗?是因为我必须在离开页面之前保存应用程序的状态吗?非常感谢:你确认了单元格数组有正确的值吗?嗯,我不知道你的意思是什么。。。你能解释清楚一点吗?谢谢,我是N00B lol:Di是指你拥有的名为
cells
的数组。它是否返回了正确的值?嗯,我想是的,但是当我翻页时,我不知道页面是否将进入原始状态,或者表视图代码是否错误?