类变量类型获取我的视图控制器改变
所以,我运行代码来填充客户的一个NSArray(定制类)对象。此自定义类具有名为Address的另一个自定义类(客户具有帐单地址和送货地址)的对象。在当列表中的用户选择了视图控制器,它通过一个新的视图控制器的客户对象,像这样:类变量类型获取我的视图控制器改变
- (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的(客户)。我的问题是关于自行车客户对象的保留和发布。 Clang Static表示客户存在过度保留错误,但是当我根据叮当解决问题时,环路崩溃。是什么赋予了?相关的代码如下:
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];
...
这听起来像你有一个以上的释放问题,因此对内存管理,你可能过度释放你正在存储你的对象的数组。虽然不能从代码片断中告诉你。你必须去查看代码并找到源代码。同样使用Clang静态分析仪可能对您有所帮助。
我编辑的这一点,但我不知道这是否显示为一个更新...... – jmeado3 2009-07-15 16:12:36