загрузка данных в UITableView, как в таблице поиска iBooks - PullRequest
2 голосов
/ 16 сентября 2010

Как я могу сказать UITableView перерисовать себя, когда я добавлю новые данные?Я выполняю этот код ib loadView метод.

[NSThread detachNewThreadSelector:@selector(addSomeData) toTarget:self withObject:nil];

Это метод addSomeData:

-(void)addSomeData{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

for (int i = 1; i <= 100; i++) {
    [myArray addObject:[NSString stringWithFormat:@"Page %i",i]];
    NSDate *d2 = [NSDate dateWithTimeIntervalSinceNow:0.2f];
    [NSThread sleepUntilDate:d2];
}

[pool release];
}

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

static NSString *CellIdentifier = @"Cell";

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

NSString *string = [myArray objectAtIndex:indexPath.row];
cell.textLabel.text = string;
// Configure the cell...
return cell;
}

myArray ist is NSArray, который содержит строку.Итак, главный вопрос - как динамически обновлять табличное представление, когда я добавляю новую строку NSString в myArray?

Ответы [ 2 ]

1 голос
/ 16 сентября 2010

[self.tableView reloadData] метод - это одно решение, которое полностью перезагружает таблицу, а [self.tableView insertRowAtIndexPath:withAnimation] - другое, которое только вставляет новую строку и анимирует изменение.

0 голосов
/ 16 сентября 2010

Попробуйте: [self.tableView reloadData];

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...