0

我想用从 web 服务接收到的 NSMutableData 填充 tableview。我可以获取数据并在多个组件上显示,但无法填充表格视图,因为以下代码不接受 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;
}
4

2 回答 2

1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [birnsarray count];
}
于 2013-04-18T07:13:54.017 回答
0

嘿,在 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;

}
于 2013-04-18T07:10:10.097 回答