Ios 如何在tableview上重新组合NSMutableArray

Ios 如何在tableview上重新组合NSMutableArray,ios,objective-c,uitableview,nsmutablearray,nsarray,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 object

以下是我在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]];
}

那么,为什么访问不方便呢?我是否以错误的方式使用了类别?

因此我猜
-getParentCategory
返回
POI_category
对象的
NSArray
-getChildCategory:
做什么?@stefandoughanthede,这是我愚蠢的错误,找到了属性(非原子,赋值)NSString*name;应该保留的时候:)谢谢你的帮助!好东西,@xeravim。需要注意的一点是,在示例代码中有两点,您声明了
POI_类别
指针和
alloc
init
一个新实例。然后将数组中的一个对象指定给指针,这样新实例将由ARC释放。本质上,您不需要
[[POI_Category alloc]init
位。
- (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;
}