嘿伙计们我有一个可以添加和删除单元格的表视图。但是当我删除应用程序附带的唯一单元格时,我尝试添加一个带有“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谢谢
答案 0 :(得分:1)
你的代码很混乱。我在下面对其进行了改进并添加了评论:
- (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;
}
答案 1 :(得分:0)
您是否将这些单元格的文本标签存储在任何类型的数组或字典中,并使用标准“cellForRowAtIndexPath?”将其加载到那里如果是这样,那么您需要删除该数据源中的字典/数组条目,以防止再次使用它。
如果没有看到更多代码,我无法确定...但这听起来像是一个细胞回收问题。我可能错了......但我需要看到更多信息。