0

In the myProj.h file I have declared:

@property (strong, nonatomic) NSMutableArray *wordsArray;

in the .m file I use the following to add some values in viewDidLoad:

[_wordsArray addObject:[NSString stringWithFormat:@"Now is the time for all good men to come to the aid of their party."]];
[_wordsArray addObject:[NSString stringWithFormat:@"Four score and seven years ago our forefathers..."]];
[_wordsArray addObject:[NSString stringWithFormat:@"A coward dies many deaths; a brave man but one."]];

I also set a counter here (defined as an int in the .h file):

__cntr = 0;

In the (IBAction)pressButton:(id)sender I want to change the label (*somelabel) text to the next value in the array [0] (then iterate _cntr to 1 and get that value, etc). So I have:

_somelabel.text = [NSString stringWithFormat:@"%@",[_wordsArray objectAtIndex:__cntr]];

Builds but when I run and press the button the label text turns to (Null).

So is the problem with the addition of the values to the array or pulling them out. Thanks

1
  • 1
    Why do you have a public property for wordsArray? Do other classes set the array or get values from it? If not, it shouldn't be a public property. Commented Jun 17, 2014 at 3:59

1 Answer 1

5

My guess is that you haven't initialized your mutable array. In viewDidLoad add:

_wordsArray = [[NSMutableArray alloc] init];

before adding any objects to it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.