IBAction 使 TabBarController 应用程序崩溃

发布于 2024-09-15 09:06:27 字数 2058 浏览 5 评论 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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后咖啡店 2024-09-22 09:06:27

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

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

玩心态 2024-09-22 09:06:27

我认为您忘记将 openModalView 方法放在 FirstViewController@interface 中。

@interface FirstViewController : UIViewController <ModalViewDelegate> {
}
- (IBAction) openModalView;
@end

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

@interface FirstViewController : UIViewController <ModalViewDelegate> {
}
- (IBAction) openModalView;
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文