【发布时间】:2012-03-23 04:25:10
【问题描述】:
我正在开发一个在表格视图中列出一些项目的 iPhone 应用程序。我在单击某个项目时遇到事件 TreasureList tableView:didSelectRowAtIndexPath 错误。我对这个错误感到困惑。错误是
[TreasureList tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x7ce0020
代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
ProductModel *data=[[ProductModel alloc]init];
data=[self.treasureData objectAtIndex:indexPath.row];
pid= [NSString stringWithFormat: data.ID];//WithFormat:@"%@",data.ID];
还请告诉我如何调试信息“deallocated instance 0x7ce0020”
我正在通过以下方式将数据添加到表格中。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
ProductModel *data=[self.treasureData objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:data.pName];
[data
release];
return cell;
}
【问题讨论】:
-
谁能帮助你?没有代码,没有错误信息,什么都没有。您需要包含相关代码。
-
添加代码以实现 didSelectRowAtIndexPath 以及与之交互的任何属性、对象、函数
-
对不起,我已经提供了代码
-
ProductModel *data=[[ProductModel alloc]init];数据=[self.treasureData objectAtIndex:indexPath.row];这两行没有意义:-P,当您从数组中使用它时,您不需要分配“数据”,我确信这个“数据”正在被释放并且您稍后会在某个地方使用它,什么属性类型你用过'treasureData'吗
-
如果您在将这些 ProductModel 对象添加到数组时没有在某处放置额外的保留/复制,则无需释放数据对象。
标签: iphone zombie-process