我在这里与此代码有问题
Book *theNewBook = [self parseTheBookXML];
// The book is not nil here
NSLog(@"The book's title: %@, number of pages:%@ and author: %@",theNewBook.title, theNewBook.pages, theNewBook.author);
[_theBooksArray addObject:theNewBook];
// TEST
Book *testBook = [_theBooksArray objectAtIndex:0];
// The book is nil here
NSLog(@"The book's title: %@, number of pages:%@ and author: %@",testBook.title, testBook.pages, testBook.author);
谁能告诉我为什么我的书本对象是“ nil”,因为我在这里撞墙了...
最佳答案
从您对我的问题的评论中可以看到,我的问题是我没有初始化要访问的数组。所以请
[_theBooksArray addObject:theNewBook];
呼唤
_theBooksArray = [[NSMutableArray alloc] initWithObjects:theNewBook, nil];
会成功的
关于ios - 从NSMutableArray获取对象时,为什么我的对象为nil?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14502337/