views:

298

answers:

1

Hello, I have a UITableView with Cells that are filled with the Objects of an NSArray. I´m using the MGTwitterEngine to get Tweets from users. I want to show this tweets in the TableView. Here is the method that is called when the MGTwitterEngine has received all tweets ("namen" and "nachricht" are NSArrays):

- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
        {   NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
         NSDictionary *userDict = [statuses valueForKey:@"user"];
         namen = [[NSArray alloc] initWithObjects: [userDict valueForKey:@"name"], nil];
         nachricht = [statuses valueForKey:@"text"];
         NSLog(@"%@", namen);
         NSLog(@"%@", nachricht);
         [table reloadData];
    }

Then I did this to fill the cells with the names of the Twitter-users:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [nachricht count];
}

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
 NSUInteger row = [indexPath row];

 cell.textLabel.text = [arryData objectAtIndex:indexPath.row];
    return cell;
}

Unfortunately, the app crashes whenever the table is reloaded: [table reloadData];. I know that the NSArray got all the right values, because NSLog shows me that. I've tried also to create a other NSArray, like that:

 arryData = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil];

And I written this into the cellforRowAtIndexPath-methode and and everything worked well. Why does it not work with the "namen"-NSArray?

+1  A: 

The NSArray is probably being released - have you examined what's at its memory address?

Mr-sk
Oh thanks. I just forgot to write [namen retain].
Flocked