2010-04-16 74 views
1

我無法把頭轉過來。當頁面加載時,一切工作正常 - 我可以向上和向下鑽取,但是當我在tableview上下拉時,'stream'(在下面突出顯示的位置)變得不等於任何東西。但錯誤只是有時候。通常它返回鍵/對。當我在桌子上上下移動時,Iphone xcode模擬器崩潰

如果知道一個可以理解上面怎麼給你一個的NSMutableDictionary對象

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *FirstLevelCell = @"FirstLevelCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell]; 
    if(cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell] autorelease]; 
    } 

    NSInteger row = [indexPath row]; 
    //NSDictionary *stream = (NSDictionary *) [dataList objectAtIndex:row]; 


    NSString *level = self.atLevel; 
    if([level isEqualToString:@"level2"]) 
    { 
     NSMutableDictionary *stream = [[NSMutableArray alloc] init]; 
     stream = (NSMutableDictionary *) [dataList objectAtIndex:row]; 

//流值是測試//(INT)[$ VAR計數]}鍵/值對 (INT) [$ VAR計數]}鍵/值對

 if ([stream valueForKey:@"title"]) 
     { 
      cell.textLabel.text = [stream valueForKey:@"title"]; 
      cell.textLabel.numberOfLines = 2; 
      cell.textLabel.font =[UIFont systemFontOfSize:10]; 

      NSString *detailText = [stream valueForKey:@"created"]; 
      cell.detailTextLabel.numberOfLines = 2; 
      cell.detailTextLabel.font= [UIFont systemFontOfSize:9]; 
      cell.detailTextLabel.text = detailText; 

      NSString *str = @"http://www.mywebsite.co.uk/images/stories/Cimex.jpg"; 
      NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]]; 
      UIImage *newsImage = [[UIImage alloc] initWithData:imageURL]; 

      cell.imageView.image = newsImage; 

      [stream release]; 
     } 
    } 
    else 
    { 
     cell.textLabel.text = [dataList objectAtIndex:row]; 
    } 


    return cell; 
} 

感謝您的時間

+0

你爲什麼要給你的字典對象分配一個可變數組然後重新賦值?你正在泄漏內存......可能不是你的問題,但仍然是一個問題 – Daniel 2010-04-16 15:16:14

回答

0

我真的不明白的問題,但是...

您可以在字典中測試值的數量:

if ([[myDictionary allKeys] count] == someNumber) { 
    // do something... 
} 
+0

代碼工作正常,但我可以'myDictionary'爲(int)[$ VAR計數]}鍵/值對 - 我需要真的爲此測試。這違反了EXC_BAD_ACCESS問題。 – Frames84 2010-04-19 08:30:45

1

你都泄漏和過度釋放流詞典:

NSMutableDictionary *stream = [[NSMutableArray alloc] init]; // <-- Create a new dictionary 
stream = (NSMutableDictionary *) [dataList objectAtIndex:row]; // <-- Overwrite the reference with another dictionary. Previous dictionary is lost... 

... 

[stream release]; // <-- You are releasing an object you don't have the ownership. 

您應該刪除字典制作,因爲它是無用的和釋放,因爲你不擁有這個對象。

相關問題