所以我有一个学生姓名的数组。我正在运行测试数据,所以我正在经历一个循环分配和初始化每个学生,然后把它扔在stuArr
- 如果我NSLog我的Student.h
init()方法它会给我我想要的名字,但当我尝试打电话他们在我的方法之外,我得到空值:Array保持返回空
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < 5; i++) {
stuArr = [stuArr arrayByAddingObject:[[Student alloc] init]];
id test = [stuArr objectAtIndexedSubscript:i];
NSLog(@"%@", [test stuName]);
}
}
我在这里失去了一些重要的东西吗?如果需要,我可以扔在我的Student.m文件,但一切似乎都很好。
也许你忘了alloc + init数组'stuArray'? – 2013-02-20 20:29:29
这不就是它在循环中做什么?现在我将NSArray作为一个在.m文件中合成的属性。 – 2013-02-20 20:30:40
那么你的学生指定的名字是? – 2013-02-20 20:30:47