IBAction崩溃TabBarController应用程序

时间:2010-08-20 02:10:21

标签: iphone uiviewcontroller uitabbarcontroller modalviewcontroller ibaction

我有一个基于Window的TabBarController应用程序,我正试图从其中一个选项卡(FirstViewController)呈现一个ModalView。该应用程序构建得很好,标签工作,但点击“打开模态视图”按钮,它崩溃并给我:

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

UPDATE :我发现问题不在于提供模态视图,而是在任何IBAction调用时都会发生崩溃。可能导致这种情况的原因是什么?

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

我知道这是很多代码,但我想确保有人能找到问题。

提前致谢!

2 个答案:

答案 0 :(得分:0)

我认为您忘记将openModalView方法放在@interface的{​​{1}}中。

FirstViewController

答案 1 :(得分:0)

您是否在IB Set to ModalViewController中的自定义视图控制器上有类?那是我的问题。