Question

I'm having issues transitioning between views and need some help. This is somewhat conviluted so bear with me please.

I have a UINavigationController called JobsNavController. The first view in JobsNavController holds a UITableViewController called JobsTableViewController [with a linked nib called JobTableView.xib]. I want to add an Add UIButton inside the UINavController to 'create a new job'. When clicked, it should flip from JobTableView.xib to my JobCreateViewController nib called JobCreateView.xib. Since the 'add' button is located within the UINavController I put the IBAction code inside JobsNavController.h and .m.

Here is the JobsNavController.h

#import <UIKit/UIKit.h>
@class JobCreateViewController, JobsTableViewController;

@interface JobsNavController : UINavigationController {
    IBOutlet UIButton *btnJobCreate;
    IBOutlet JobCreateViewController *jobCreateViewController;
        IBOutlet JobsTableViewController *jobsTableViewController;
}
-(IBAction)tellDelegateToFlip:(id)sender;

@property (nonatomic, retain) UIButton *btnJobCreate;
@property (nonatomic, retain) IBOutlet JobCreateViewController *jobCreateViewController;
@property (nonatomic, retain) IBOutlet JobsTableViewController *jobsTableViewController;

@end

And here is my JobsNavController.m

#import "JobsNavController.h", "Time_Blogger1AppDelegate.h", "JobsTableViewController.h"
@implementation JobsNavController
@synthesize btnJobCreate, jobCreateViewController, jobsTableViewController;
.....
-(void)tellDelegateToFlip {
    JobCreateViewController *jobAddView = [jobCreateViewController initWithNibName:@"JobCreateView" bundle:nil];

    [self setJobCreateViewController:jobAddView];
    [jobAddView release];

    UIViewController *transitionTo = jobCreateViewController;

    //create view animation block
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    [jobsTableViewController.view removeFromSuperview];
    [self.view insertSubview:transitionTo.view atIndex:0];
    [UIView commitAnimations];

    [transitionTo release];
}

I'm not getting any build/compile errors but the simulator throws an exception when I click the button stating:

2012-01-22 19:19:22.895 Time-Blogger1[4209:f803] 
-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80 2012-01-22 19:19:22.897 Time-Blogger1[4209:f803] 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[JobsNavController tellDelegateToFlip:]: unrecognized selector sent to instance 0x6c85e80'
Was it helpful?

Solution

When you call tellDelegateToFlip make sure you do it with no parameters- this is what is causing the crash. If you notice in the crash report, it says the unrecognized selector tellDelegateToFlip: is being sent to your instance. Notice the colon coming after the method name. This means that wherever you called the method, you sent an object with it. If you are using performSelector:withObject:afterDelay: make sure you don't use a colon.

Edit:

Instead of:

UIViewController* transitionTo = jobCreateViewController;

why don't you just use:

JobCreateViewController* transitionTo = jobCreateViewController;

Or you could cast it, assuming that JobCreateViewController inherits from UIViewController.

OTHER TIPS

wrong implementation of the method:

-(IBAction)tellDelegateToFlip:(id)sender;

should be:

-(IBAction)tellDelegateToFlip:(id)sender {
...
}

in your JobsNavController.m

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top