Where would I implement this array to pass?

Posted by Keeano Martin on Stack Overflow See other posts from Stack Overflow or by Keeano Martin
Published on 2013-06-30T22:53:28Z Indexed on 2013/07/01 4:21 UTC
Read the original article Hit count: 432

Filed under:
|
|

I currently build an NSMutableArray in Class A.m within the ViewDidLoad Method.

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Question Array Setup and Alloc
    stratToolsDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:countButton,@"count",camerButton,@"camera",videoButton,@"video",textButton,@"text",probeButton,@"probe", nil];
    stratTools = [[NSMutableArray alloc] initWithObjects:@"Tools",stratToolsDict, nil];
    stratObjectsDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratTools,@"Strat1",stratTools,@"Strat2",stratTools,@"Strat3",stratTools,@"Strat4", nil];
    stratObjects = [[NSMutableArray alloc]initWithObjects:@"Strategies:",stratObjectsDict,nil];
    QuestionDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratObjects,@"Question 1?",stratObjects,@"Question 2?",stratObjects,@"Question 3?",stratObjects,@"Question 4?",stratObjects,@"Question 5?", nil];


    //add strategys to questions
    QuestionsList = [[NSMutableArray alloc]init];
    for (int i = 0; i < 1; i++) {
        [QuestionsList addObject:QuestionDict];
    }
    NSLog(@"Object: %@",QuestionsList);

At the end of this method you will see QuestionsList being initialized and now I need to send this Array to Class B.

So I place its setters and getters using the @property and @Synthesize method. Class A.h

@property (retain, nonatomic) NSMutableDictionary *stratToolsDict;
@property (retain, nonatomic) NSMutableArray *stratTools;
@property (retain, nonatomic) NSMutableArray *stratObjects;
@property (retain, nonatomic) NSMutableDictionary *QuestionDict;
@property (retain, nonatomic) NSMutableArray *QuestionsList;

Class A.m

@synthesize QuestionDict;
@synthesize stratToolsDict;
@synthesize stratObjects;
@synthesize stratTools;
@synthesize QuestionsList;

I use the property method because I am going to call this variable from Class B and want to be able to assign it to another NSMutableArray.

I then add the @property and @class for Class A to Class B.h as well as declare the NSMutableArray in the @interface.

#import "Class A.h"

    @class Class A;

    @interface Class B : UITableViewController<UITableViewDataSource, UITableViewDelegate>{
        NSMutableArray *QuestionList;
        Class A *arrayQuestions;
      }

    @property Class A *arrayQuestions;

Then I call NSMutableArray from Class A in the Class B.m

-(id)initWithStyle:(UITableViewStyle)style
{
    if ([super initWithStyle:style] != nil) {

        //Make array
        arrayQuestions = [[Class A alloc]init];
        QuestionList = arrayQuestions.QuestionsList;

Right after this I Log the NSMutableArray to view values and check that they are there and it returns NIL.

//Log test
NSLog(@"QuestionList init method: %@",QuestionList);

Info about Class B- Class B is a UIPopOverController for Class A, Class B has one View which holds a UITableView which I have to populate the results of Class A's NSMutableArray.

Why is the NsMutableArray coming back as NIL? Ultimately would like some help figuring it out as well, it seems to really have me confused. Help is greatly appreciated!!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iPad