Заполнение таблицы с помощью nsmutabledata, полученного от веб-службы
Я хотел бы заполнить табличное представление с NSMutableData, который получен от веб-сервиса. Я могу получить данные и отобразить их в нескольких компонентах, но не могу заполнить табличное представление, потому что следующий код не принимает NSMutableData;
AnyNSarray = [NSPropertyListSerialization propertyListWithData: webData options: 0 format:&plf error: &error];
//webData is NSMutableData that i populate with webservice data and AnyNSarray is a NSArray to provide tableview at
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Вот блоки заполнения табличного представления (также следующий код работает при загрузках представления, но не запускается снова после нажатия кнопки):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"cell%i",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text = [birnsarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text = @"any details";
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return AnyNSarray.count;
}
2 ответа
Решение
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [birnsarray count];
}
Привет в функции numberOfRows вы возвращаете счетчик AnyNSarray, поэтому замените свой cellForRowAtIndexPath на приведенный ниже код.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"cell%i",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text = [AnyNSarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text = @"any details";
}
return cell;
}