0

我有一个基于窗口的 TabBarController 应用程序,我正在尝试从其中一个选项卡 (FirstViewController) 中呈现 ModalView。该应用程序构建得很好并且选项卡工作,但是在单击“打开模式视图”按钮时,它崩溃并给我:

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

更新:我发现问题不在于呈现模式视图,而是任何 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

模态视图控制器.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

模态视图控制器.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

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

提前致谢!

4

2 回答 2

0

我想你忘了把 openModalView 方法放在@interface.FirstViewController

@interface FirstViewController : UIViewController <ModalViewDelegate> {
}
- (IBAction) openModalView;
@end
于 2010-08-20T03:15:44.763 回答
0

您是否将 IB 中的自定义视图控制器上的类设置为 ModalViewController?那是我的问题。

于 2011-02-03T05:54:41.343 回答