0

I would like to populate a tableview with a NSMutableData that received from a webservice. I can get the data and display at several components but cannot fill the tableview because following code doesn't accept 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 

Here is tableview populating blocks (also following code works at view loads but is not fired again after i click button):

- (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;
}
Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Murat Calim
  • 580
  • 1
  • 6
  • 11
  • 2
    What object types the array contains? It will work only if the types are NSString. Notice that you don't reuse your cells with this format cell%i. Because the identifier is never the same. – pbibergal Apr 18 '13 at 06:52
  • you are using birnsarray in this line, cell.textLabel.text = [AnyNSarray objectAtIndex:indexPath.row]; – BhushanVU Apr 18 '13 at 06:56

2 Answers2

1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [birnsarray count];
}
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
0

Hey in numberOfRows function you are returning AnyNSarray count, so replace your cellForRowAtIndexPath with the below code.

- (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;

}
Satheesh
  • 10,998
  • 6
  • 50
  • 93