如何在tableview上重新组合NSMutableArray

时间:2014-08-26 10:21:06

标签: ios objective-c uitableview nsmutablearray nsarray

这是我在viewDidLoad中重新组合数组的方法:

arrayChild=[[NSMutableArray alloc]init];
arrayTitle=[[NSMutableArray alloc]init];
arrayParent=[CM getParentCategory];
for (int i=0; i<arrayParent.count; i++) {
    c=[[POI_Category alloc]init];
    c=[arrayParent objectAtIndex:i];
    [arrayTitle addObject:c.name];
    [arrayChild addObject:[CM getChildCategory:c._id]];
}

并在cellForRow中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"categoryCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


cell.accessoryType = UITableViewCellAccessoryNone;
@try {
   POI_Category *category=[[POI_Category alloc]init];
    category=[[arrayChild objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    [cell.textLabel setText:category.name]; //This line always get EXC_BAD_ACCESS (code=2, address=0x10)
}
@catch (NSException *exception) {
    NSLog(@"exc:%@",exception);
}


return cell;
}

那么为什么访问不好?我是否以错误的方式使用该类别?

0 个答案:

没有答案