IBAction 使 TabBarController 应用程序崩溃
我有一个基于窗口的 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
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否将 IB 中的自定义视图控制器上的类设置为 ModalViewController?那是我的问题。
Do you have the class on your custom view controller in IB Set to ModalViewController? That was my problem.
我认为您忘记将 openModalView 方法放在
FirstViewController
的@interface
中。I think you forgot to put the openModalView method in the
@interface
ofFirstViewController
.