I have a NSMutableArray and I would like to use data from it in another view. I read up and found we can use indexOfObject to read data, but my NSMutableArray has multiple values, and I do not know how to obtain a particular field from the NSMutableArray.
Any help would be great appreciated.
I’m currently stuck at my IBAction onStartPressed. at the line
self.clueHint.text = ds[0].initialClue;
//or
self.clueHint.text = ds objectAtIndex:0 initialClue;
I displayed my other file and code which is involved.
ClueData.h
#import
@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];
}
in the IBAction, first cast/save it to the correct var, like
ClueData * sampleData = [ds objectAtIndex:0];
then self.clueHint.text= [sampleData initialClue];
as example