У меня есть UITableView с ячейками, которые заполнены объектами NSArray. Я использую MGTwitterEngine для получения твитов от пользователей. Я хочу показать эти твиты в TableView. Вот метод, который вызывается, когда MGTwitterEngine получил все твиты ("namen" и "nachricht" - 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];
}
Затем я сделал это, чтобы заполнить ячейки именами пользователей Twitter:
- (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;
}
К сожалению, приложение аварийно завершает работу при перезагрузке таблицы: [table reloadData];
. Я знаю, что NSArray получил все правильные значения, потому что NSLog показывает мне это. Я также пытался создать другой NSArray, например:
arryData = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil];
И я записал это в cellforRowAtIndexPath-метод, и все работало хорошо. Почему не работает с "namen" -NSArray?