2012-03-23 29 views
-2

我正在一個iPhone應用程序中列出一些表格視圖中的項目。我遇到錯誤事件TreasureList tableView:didSelectRowAtIndexPath,同時點擊一個項目。我對這個錯誤感到困惑。該錯誤是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]; 

也請讓我知道我可以調試信息「釋放的實例0x7ce0020」

我將數據添加到tableivew採取以下方式。

- (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; 
} 
+0

任何人都可以幫助你嗎?沒有代碼,沒有錯誤信息,什麼都沒有。你需要包含相關的代碼。 – bryanmac 2012-03-23 04:31:34

+0

爲您的didSelectRowAtIndexPath實施添加代碼,以及它與之交互的任何屬性,對象,函數 – bryanmac 2012-03-23 04:33:21

+0

對不起,我已經提供了代碼 – MACMAN 2012-03-23 04:45:41

回答

1

@Gijo你可能會得到這個錯誤,由於一些消息已經被髮​​送,你要麼用你的表格單元格,或當你試圖在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
使用的東西已經釋放的對象

方法,它已經被釋放,即一些對象,標籤等。

+0

這是否與自定義單元格有關? – MACMAN 2012-03-23 04:58:17

+0

是的幾乎可能,請放一些代碼並相應地更新您的問題。在詢問任何與崩潰或其他相關的任何事情時,總是會感激代碼:-) – 2012-03-23 05:01:21

+0

我用我用來填充Tableview的代碼修改了我的原始問題。 – MACMAN 2012-03-23 05:15:53