【发布时间】:2011-02-23 22:20:44
【问题描述】:
我有一个定义为属性的 NSMutableArray,已合成并分配了一个新创建的 NSMutableArray 实例。但在此之后,每当我尝试向 NSMutableArray 添加对象时,我的应用程序总是崩溃。
Page.h
@interface Page : NSObject
{
NSString *name;
UIImage *image;
NSMutableArray *questions;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, copy) NSMutableArray *questions;
@end
Page.m
@implementation Page
@synthesize name, image, questions;
@end
相关代码
Page *testPage = [[Page alloc] init];
testPage.image = [UIImage imageNamed:@"Cooperatief leren Veenman-11.jpg"];
testPage.name = [NSString stringWithString:@"Cooperatief leren Veenman-11.jpg"];
testPage.questions = [[NSMutableArray alloc] init];
[testPage.questions addObject:[NSNumber numberWithFloat:arc4random()]];
调试器显示,在我使用testPage.questions = [[NSMutableArray alloc] init]; 的那一刻,testPage.questions 的类型从 NSMutableArray* 变为 __NSArrayL*(或 __NSArrayI*,不确定)。我怀疑这是问题所在,但我觉得这非常奇怪。有人知道这里发生了什么吗?
【问题讨论】:
标签: iphone objective-c nsmutablearray nsarray type-conversion