【发布时间】:2009-11-16 15:46:17
【问题描述】:
@implementation Level
@synthesize doors, rooms;
- (id) init
{
self = [super init];
if (self != nil) {
rooms = [[NSMutableArray alloc] init];
doors = [[NSMutableArray alloc] init];
}
return self;
}
- (void)generate{
int room_count = 2;
Room *room;
for (int i=0; i<room_count; i++) {
room = [[Room alloc] init];
[room generate_Doors];
[self.rooms addObject:room];
[room release];
}
for (int i=0; i<[rooms count]; i++) {
Room *r=[rooms objectAtIndex:i];
//After this point rooms is invalid
int l=[[r doors] count];
for (int j=0; j<l; j++) {
Door *d=[[[rooms objectAtIndex:i] doors] objectAtIndex:j];
[self.doors addObject:d];
}
}
}
这是我在调试器中看到的
alt text http://img163.imageshack.us/img163/8090/20091117174111.png
【问题讨论】:
-
我认为您误解了从调试器获得的结果。做一些 NSLog 调试以确保。例如在您的评论下方添加以下行:NSLog(@"我们的列表中还有什么东西吗 - 让我们看看对象计数 %d", [房间计数]);
-
对此,请尝试
NSLog(@"First object: %@", [rooms objectAtIndex:0]);。
标签: iphone cocoa cocos2d-iphone nsmutablearray