因此,在我的视图控制器,我运行代码以填充客户的一个NSArray(自定义类)的对象。这种定制类有是另一种自定义类称为地址(一个客户有一个帐单地址和送货地址)对象。在当在列表的客户所被选择的视图控制器,它通过一个新的视图控制器客户对象,像这样:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    InfoViewController *customerinfoViewController = [[InfoViewController alloc] initWithStyle:UITableViewStyleGrouped andCustomer:[[[customers objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] retain]];
    [self.navigationController pushViewController:customerinfoViewController animated:YES];
    [customerinfoViewController release];
}

在第一次运行应用程序时我访问这个视图控制器,它工作正常。然而,当我重温视图控制器,一些有趣的事情发生了。该应用程序崩溃,无法识别的选择发送到实例0x00whatever。在Xcode使用鼠标悬停调试功能,我发现了客户的shipAddress变量的第一个对象的类型从NSString的改变NSIndexPath。这不会发生到客户的billAddress对象。任何人有任何想法是怎么回事?好像我可能会遇到内存管理问题,但我肯定会喜欢这个确认之前,我撕我的代码除了跟踪了所有的保留和释放....

编辑:这里的详细信息。用下面的代码,我有一个NSMutableArray类级别。在循环的每次迭代中,我通过XML节点循环(工作正常)。每一个新的字母被检测为名称的第一个字母时,我创建了一个新的子阵和客户添加到它,从而填补与检测到的每个字母的客户子阵列我的类级NSMutableArray的(客户)。我的问题是关于保留和骑自行车的客户对象的版本。锵静态说,有对客户的过度保留的错误,但是当我修复根据铛,循环崩溃了。是什么赋予了?下面相关的代码:

DDXMLDocument *rootDoc = [[[DDXMLDocument alloc] initWithData:xmlData options:0 error:nil] autorelease];
NSArray *elems = [rootDoc nodesForXPath:@"QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet" error:nil];
DDXMLNode *node;
sectionTitles = [[[NSMutableArray alloc] initWithCapacity:1] retain]; // Letters for UITableView section titles
NSMutableArray *subArray;
NSString *lastchar = @"A";
NSString *testchar; 
int indexCount = -1;
customers = [[[NSMutableArray alloc] initWithCapacity:[elems count]] retain];
Customer *newCust;
for (int i = 0; i < [elems count]; i++) {
    node = [elems objectAtIndex:i];
    newCust  = [[Customer alloc] initWithCustomerRetNode:node];
    testchar = [[newCust fullName] substringToIndex:1];
    if (i == 0 || ![[testchar uppercaseString] isEqualToString:lastchar]) {
        [sectionTitles addObject:testchar];
        lastchar = testchar;
        indexCount++;
        subArray = [[NSMutableArray alloc] initWithCapacity:1];
        [customers addObject:subArray];
        [subArray release];
        [[customers lastObject] addObject:[newCust retain]];
    }
    else {
        [[customers lastObject] addObject:[newCust retain]];
    }
    [newCust release];
}

注:此代码工作的大部分,但铛不喜欢

编辑:地址在客户类被分配像这样(现在不锵修复后工作)

...
else if ([tempname isEqualToString:@"BillAddress"])
  billAddress = [billAddress initWithAddressNode:tempnode];
else if ([tempname isEqualToString:@"ShipAddress"])
  shipAddress = [shipAddress initWithAddressNode:tempnode];
...
有帮助吗?

解决方案

这听起来像你有一个以上的释放问题,因此对内存管理,你可能会overreleasing数组你存储你的对象in.Cant真正从代码段的告诉虽然。 youll必须去通过代码看,找到源头。还使用锵静态分析可能是对您有所帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top