我有一個NSMutableArray,我想在另一個視圖中使用它的數據。我讀了,發現我們可以使用indexOfObject讀取數據,但我的NSMutableArray有多個值,我不知道如何從NSMutableArray獲得特定的字段。從NSMutableArray檢索對象
任何幫助將不勝感激。
我目前被困在我的IBAction onStartPressed。在線
self.clueHint.text = ds[0].initialClue;
//or
self.clueHint.text = ds objectAtIndex:0 initialClue;
我顯示了我涉及的其他文件和代碼。
ClueData.h #進口
@interface ClueData : NSObject
@property(nonatomic, strong) NSString * clueName;
@property(nonatomic, strong) NSString * initialClue;
@property(nonatomic, strong) NSString * clueHint1;
@property(nonatomic, strong) NSString * clueHint2;
@property(nonatomic, strong) NSString * clueAnswer;
@property(nonatomic, strong) UIImage * clueImage;
@end
ClueDataDAO.h
#import <Foundation/Foundation.h>
#import "ClueData.h"
@interface ClueDataDAO : NSObject
@property(strong, nonatomic) NSMutableArray * clueDataArray;
-(NSMutableArray *) PopulateDataSource;
@end
ClueDataDAO.m
#import "ClueDataDAO.h"
@implementation ClueDataDAO
@synthesize clueDataArray;
-(NSMutableArray *) PopulateDataSource
{
clueDataArray = [[NSMutableArray alloc]init];
ClueData * sampleData = [[ClueData alloc]init];
sampleData.clueName = @"Tropical Fruit Tree";
sampleData.initialClue = @"Where all the Tropical trees are planted.";
sampleData.clueHint1 = @"It is located at Area 10";
sampleData.clueHint2 = @"It could be found near Eco Lake";
sampleData.clueAnswer = @"Fruit tree collection";
NSString * file=[[NSBundle mainBundle]pathForResource:@"FruitTreeCollection" ofType:@"jpg"];
sampleData.clueImage = [UIImage imageWithContentsOfFile:file];
[clueDataArray addObject:sampleData];
sampleData=nil;
return clueDataArray;
}
@end
GamePageViewController.M
- (void)viewDidLoad
{
[super viewDidLoad];
daoDS = [[ClueDataDAO alloc]init];
self.ds = daoDS.PopulateDataSource; //load pre-build NSMutableArray
self.answer.delegate = self;
// Do any additional setup after loading the view.
}
- (IBAction)onStartPressed:(id)sender {
//initiate load object
// stuck at here :(
ClueData * currentClue = [ds objectAtIndex:0]; // app got terminate at this line of code
self.clueHint.text = [currentClue initialClue];
}
在IBAction爲,第一鑄造/保存到正確的變種
你是什麼意思「我的數組有多個字段」?那麼,這就是爲什麼它被稱爲一個數組而不是一個原始類型......此外,**使用空格。** @property(強,非原子)NSMutableArray * clueDataArray;'只是徹底傷害。同樣,這個問題**與Xcode沒有任何關係。** – 2012-10-14 11:32:14
我認爲他的意思是:每個對象都有多個項目,所以NSDict的基礎知識或(自定義)類作爲數組的項目。 –
對不起..我是一個noob ...仍然是新的... –