문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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

@interface FirstViewController : UIViewController <ModalViewDelegate> {
}
- (IBAction) openModalView;
@end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top