Question

I have a Window-based TabBarController app and I'm trying to present a ModalView from one of the tabs (FirstViewController). The app builds just fine and the tabs work, but upon clicking the "Open Modal View" button, it crashes and gives me:

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

UPDATE: I have found that the issue is not with presenting the modal view but the crash happens with any IBAction calls. what could be causing this?

FirstViewController.h:

#import <UIKit/UIKit.h>
#import "ModalViewController.h"

@interface FirstViewController : UIViewController <ModalViewDelegate> {}
@end

FirstViewController.m:

#import "FirstViewController.h"

@implementation FirstViewController
- (IBAction) openModalView {
    ModalViewController *modalView=[[ModalViewController alloc] init];
    modalView.modalDelegate=self;
    [self presentModalViewController:modalView animated:YES];
    [modalView release];
}

 #pragma mark -
 #pragma mark ModalViewDelegate

- (void) didHitCancel {
    [self dismissModalViewControllerAnimated:YES];
}

 #pragma mark - 

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
    [super viewDidUnload];
}
- (void)dealloc {
    [super dealloc];
}

@end

ModalViewController.h:

 #import <UIKit/UIKit.h>

@protocol ModalViewDelegate <NSObject>
- (void)didHitCancel;
@end

@interface ModalViewController : UIViewController {
    id modalDelegate;
}

@property (nonatomic, assign) id<ModalViewDelegate> modalDelegate;

- (IBAction) cancel;

@end

ModalViewController.m:

 #import "ModalViewController.h"

@implementation ModalViewController

@synthesize modalDelegate;

- (IBAction) cancel {
    [self.modalDelegate didHitCancel];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
 }
 - (void)viewDidUnload {
    [super viewDidUnload];
}
- (void)dealloc {
    [super dealloc];
}

@end

I know this is a lot of code but I wanted to make sure someone could find the problem.

Thanks in advance!

Was it helpful?

Solution

Do you have the class on your custom view controller in IB Set to ModalViewController? That was my problem.

OTHER TIPS

I think you forgot to put the openModalView method in the @interface of FirstViewController.

@interface FirstViewController : UIViewController <ModalViewDelegate> {
}
- (IBAction) openModalView;
@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top