English 中文(简体)
NSMutable array invalid after objectAtIndex
原标题:
@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];
    }
  }

}

This is that i ve seen in debugger

alt text http://img163.imageshack.us/img163/8090/20091117174111.png

最佳回答

The debug window does that sometimes. "Out of Scope" when it isn t.

Not much you can do about it, it s a bit of a bug in XCode. Just because the debugger can t show you the value in the window, doesn t mean the object is gone.

Have a read here on this stackoverflow.com question about debugging. It has some very nice debugging information. Good stuff to know!

问题回答

The debugging fragment you show does not indicate rooms is invalid, just that it is not displaying the values you expect - if you stop in the debugger after the loop and type in the debugger console:

po rooms

What does it display?

The code you have looks fine.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签