views:

89

answers:

4

In my view controller (viewDidLoad) I am populating an array defined in the view controllers header file with settings data (from an archive). I am using data from the array to write labels on buttons in the view, no problem so far.

I would like to pass one element of the array through an IBAction to add to the new view controller. I keep getting an error from within the IBAction

'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5d230f0').

Here is the relevant part of my IBAction code:

-(IBAction)pushedTimer:(id)sender {
    if (!timerViewController) {
        timerViewController = [[TimerViewController alloc] init];
    }
    [timerViewController setPreset:[[settingsArray objectAtIndex:0] settingLength]];
    [[self navigationController] pushViewController:timerViewController animated:YES];
}

I was thinking that since the array is accessible in other methods, it should also work with the IBAction? The error leads me to believe that the IBAction can not determine that the settingsArray is really an array?

Thanks again.

+1  A: 

Do instances in settingArray implement settingLength?

The question was itself a answer. I meant instances should implement settingLength.

alones
Hey @alones, if you want to make a question, use the comment are bellow the question. -1!
vfn
@vfn: Users require a certain amount of reputation before they are able to post comments. It is not abundantly obvious to new users that this is the case so the downvote is not necessary.
dreamlax
@alones, It doesn't justify to add a answer! It doesn't bring any benefits, actually it only represents noise.
vfn
+1  A: 

How are you defining the settingArray? Are you creating a @property and @synthesizing it? If you're not, then you can't access that in allocated instances of that object, so your array will be nil. Also make sure to check what @alones said!

MishieMoo
@MishieMoo, if you want to make a question, use the comment are bellow the question. -1!
vfn
@vfn I don't have 50 rep points. See drealmax's comment on alones post above...
MishieMoo
As I comment on @alone, it doesn't justify you post a question on the space used for answers. Edit your answer and I can remove the vote down.
vfn
Odd, this one downvote is the only thing keeping you from commenting. My head is spinning.
Will
A: 

-[NSCFString objectAtIndex:]: unrecognized selector sent sounds like settingsArray is a NSString, not a NSArray.

Thomas Müller
@Thomas Muller: It was originally created as an NSArray, but it ends up it was getting autoreleased and camping on an memory address of some string. Thanks for your support.
derrick
+2  A: 

I am not sure but here is what I think for this common problem:

Your array is garbaged already. What this means is that your array is dealloc somewhere in your code (by your over call of release or autorelease) then the string is allocated into the same memory area of the array. So that when the system try to call the object in that memory area, it is calling a NSString object not a NSArray object anymore.

You should double check all the release and autorelease of your array

vodkhang
@vodkhang, @vfn - The array was indeed being released (autoreleased). A simple retain until manually releasing solved the issue. THANK YOU very much.
derrick
Maybe because you are here at the first time, but you can accept answers. That will increase your accept rate and motivate other people
vodkhang
Got it, thanks for your patience.
derrick