我有兩個類。首先下載數據映像並將它們逐個添加到陣列中。當它完成後,所有16個人都會將視圖切換到第二個視圖。我的問題在於如何從第二課的第一課訪問數組?從不同的視圖控制器訪問陣列
下面是代碼:
first.h
@interface first{
NSMutableArray *imagesArray;
}
@property(nonatomic,retain)NSMutableArray *imagesArray;
(陣列在.m文件synthetized)
second.h
#import"second";
#import"first.h"
second.m
-(void) viewdidload {
first *another = [[another alloc] init];
label.text = [NSString stringWithFromat:@"%i",[another.imagesArray count]];
imageView.image = [another.imagesArray objectAtIndex:0];
}
label
表示0和imageView
說明不了什麼。有任何想法嗎?
你可以創建全局數組或者在** second.h **中定義相同的@property(nonatomic,retain)NSMutableArray * imagesArray;'當你從First到Second時,傳遞該數組。所以你不需要分配第一個視圖。 – 2014-09-02 04:19:59
http://stackoverflow.com/questions/6678097/how-to-pass-an-array-from-one-view-controller-to-another和http://stackoverflow.com/questions/15789163/add-objects從另一個視圖控制器到陣列可能會有所幫助 – 2014-09-02 04:31:50