views:

542

answers:

3

Hi,

I have a button in a view which refuses to work. I've got in working in a blank, default view application from X-Code, but in none of my applications will it work, instead it gives me the following error.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UIViewController showVicInfo:]: unrecognized selector sent to instance 0x3c084f0'

The debugger isn't any help either. I've made sure that I hook up the button to the file's owner (not the other way around) as well. Below is the code for the action. And I know it's not the alert view, because the breakpoint doesn't even reach there.

about.h

    @interface about : UIViewController {

}

-(IBAction)showVicInfo:(id)sender;

about.m

-(IBAction)showVicInfo:(id)sender {
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for iFirelert to work." delegate:self cancelButtonTitle:@"OK, thanks" otherButtonTitles:nil];
    [myAlert show];
    [myAlert release];
}

Update: FYI this is how I went about creating the button,if it helps.

  1. Created new view (File>New File>UIViewControllerSubclass w/XIB for interface)
  2. Added -(IBAction)showInfo:(id)sender; to about.h
  3. Added
  4. -(IBAction)showVicInfo:(id)sender { UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for iFirelert to work." delegate:self cancelButtonTitle:@"OK, thanks" otherButtonTitles:nil]; [myAlert show]; [myAlert release]; } to about.m
  5. Opened About.xib in Interface Builder, dragged a Rectangular Button onto the View
  6. Hooked up the button to the -showVicInfo action by ctrl-clicking the button to the File's Owner property (not the other way around).
  7. Checked the File's Owner was set to "about" class which it is.

And then built and run with failure in X-Code.

Update 2: OK, I've worked out it must be a setting or something in my existing project.I've copied the two class files and XIB file which does work in another X-Code project, but the button also throws the same error in the existing app.

+1  A: 

I think Squeegy is right, your VC is a plain old UIViewController and doesn't accept showVicInfo.

Did you set the class (command-4) for your ViewController in IB?

Or if you are allocating it yourself, are you doing it like this:

vc = [UIViewController alloc];    // wrong class

when you should be doing this:

vc = [about alloc];     

The error message is telling you that showVicInfo was being sent to 0x3c084f0. Check the address of the view controller that you created (like the value in "vc" above), if it's 0x3c084f0 that's your answer. Of course the value may be different next time, but NSLog it when you create it and then compare it to the error message to know for sure what it is referring to.

Check also that you have the button hooked up correctly in IB. If you select the button and go to the Button Connections tab you should have connections. For Touch Up Inside should connect to your action function, in your IB it should connect to showVicInfo:

progrmr
Unfortunately it is set to about. Any other ideas?
Graeme
Have added update above on how I made the button and added connection - something wrong perhaps?
Graeme
Why do you have showInfo: in the .h and showVicInfo: in the .m file? The names should match, either both showInfo or both showVicInfo. Are you positive the error message said showVicInfo? could it have said showInfo?
progrmr
Hmm don't know how that got there in the above code, but in XCode they both say showVicInfo!
Graeme
Also I can't see that screenshot - it's blank and when I click on it it asks me to login to another website.
Graeme
A: 

Did you ever end up resolving this? I am having the same issue.

Devraj
A: 

Had the same error. The problem was that I released the viewController.

AnswerStructureViewController* questionVC = [[AnswerStructureViewController alloc] initWithOpts:dict];
[window addSubview:questionVC.view];
[questionVC release];

Everything is fine if you don't release it

Ivan