Iphone 两个视图中的数组计数不同

Iphone 两个视图中的数组计数不同,iphone,nsmutablearray,Iphone,Nsmutablearray,我在一个类中向数组添加值&在另一个类中访问该数组。这是我的代码=> abcView.dateArray = [[NSMutableArray alloc]init]; // fetch data from db & assign to date [abcView.dateArray addObject:date]; NSLog(@"Count value of dateArray =>%d",[abcView.dateArray count]);

我在一个类中向数组添加值&在另一个类中访问该数组。这是我的代码=>

abcView.dateArray = [[NSMutableArray alloc]init];
// fetch data from db &  assign to date
        [abcView.dateArray addObject:date];
        NSLog(@"Count value of dateArray =>%d",[abcView.dateArray count]);
这里我得到的是count as=>3的结果

之后,我将尝试在abcViewController.m的viewDidLoad方法中访问该数组,如下所示

NSInteger countVal = [dateArray count];
NSLog(@"dateArray count =>%d",countVal);
这里我得到的计数结果为=>0


请帮帮我。。。谢谢

请确保在第二种情况下dateArray不是零

如果dateArray是视图的属性,则必须遍历视图才能从视图控制器访问它。例如,如果要将ABCViewController的视图设置为名为ABCView的UIView子类的实例,则控制器代码可能如下所示:

NSInteger countVal = [((ABCView *)self.view).dateArray count];

这个问题无法回答。我不知道这些dateArray对象是否是同一个对象,即使是,也不知道您是在同一时间(ish)访问它们还是在其间更改数组。而且,第一个代码段显然是错误的,因为分配一个数组并向其中添加一项不会导致计数为3。请使用调试器跟踪代码以查看发生了什么,或者在问题中提供更多的上下文,但是在这个问题上进行自己的调试可能会更简单。