使用 UIButtons 打开不同的 .nib

发布于 2024-11-19 11:19:47 字数 2233 浏览 1 评论 0原文

某些东西无法正常工作,我无法弄清楚为什么这无法加载我的其他笔尖,目前这可以工作,

#pragma mark - Flipside View

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showInfo:(id)sender
{    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

而我在同一个 MainViewController.m 并且在执行此操作时没有成功,

#pragma mark - News View

- (void)newsViewControllerDidFinish:(NewsViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

所以我认为我的头文件有问题,看起来像这样

    #import "FlipsideViewController.h"
#import "NewsViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, NewsViewControllerDelegate>

- (IBAction)showInfo:(id)sender;
- (IBAction)showNews:(id)sender;

@end

我无法弄清楚为什么它不起作用,任何帮助将不胜感激。

输出错误:

此 GDB 已配置为“x86_64-apple-darwin”。正在附加到 过程2147。 2011-07-08 12:24:09.845 丹尼[2147:ef03] -[NewsViewController setDelegate:]: 无法识别的选择器 发送到实例 0x68a62b0 2011-07-08 12:24:09.847 Danny[2147:ef03] * 终止应用程序 由于未捕获的异常 'NSInvalidArgumentException',原因: '-[NewsViewController setDelegate:]: 无法识别的选择器发送到实例 0x68a62b0' * 首先抛出调用堆栈: (0xf8a600 0x112252e 0xf8d550 0xeeb4cf 0xeeb292 0x2a36 0xf8bd78 0x18cc5 0x18c5a 0xbdbd4 0xbe09d 0xbd368 0x3e004 0x3e22d 0x24990 0x181a7 0x1369886 0xf59d11 0xebbc9b 0xeba4b1 0xeb993c 0xeb9868 0x1367fef 0x13680b4 0x160c4 0x2009 0x1f75) 终止调用抛出异常sharedlibrary 应用加载规则全部 当前语言:自动;目前objective-c (gdb)

something isn't working right and i can't work out why this isn't working to load my other nib, this currently works

#pragma mark - Flipside View

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showInfo:(id)sender
{    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

whilst i've done the exact same thing here on the same MainViewController.m and had no success whilst doing it

#pragma mark - News View

- (void)newsViewControllerDidFinish:(NewsViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

so i think there is something wrong with my header file which looks like this

    #import "FlipsideViewController.h"
#import "NewsViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, NewsViewControllerDelegate>

- (IBAction)showInfo:(id)sender;
- (IBAction)showNews:(id)sender;

@end

I can't work out why it's not working, any help would be appreciated.

Error from output:

This GDB was configured as "x86_64-apple-darwin".Attaching to
process 2147.
2011-07-08 12:24:09.845 Danny[2147:ef03] -[NewsViewController
setDelegate:]: unrecognized selector
sent to instance 0x68a62b0
2011-07-08 12:24:09.847 Danny[2147:ef03] * Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NewsViewController setDelegate:]:
unrecognized selector sent to instance
0x68a62b0'
*
First throw call stack:
(0xf8a600 0x112252e 0xf8d550 0xeeb4cf 0xeeb292 0x2a36 0xf8bd78
0x18cc5 0x18c5a 0xbdbd4 0xbe09d
0xbd368 0x3e004 0x3e22d 0x24990
0x181a7 0x1369886 0xf59d11 0xebbc9b
0xeba4b1 0xeb993c 0xeb9868 0x1367fef
0x13680b4 0x160c4 0x2009 0x1f75)
terminate called throwing an exceptionsharedlibrary
apply-load-rules all
Current language: auto; currently objective-c
(gdb)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

檐上三寸雪 2024-11-26 11:19:47

视图控制器的委托方法是什么?检查委托方法的声明是否相同。确保您已正确设置代表

What is the delegate method for the view controller? Check if the declaration of the delegate method is the same. Make sure you have set the delegates properly

澜川若宁 2024-11-26 11:19:47

试试这个:

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

在新闻视图中,不要写

[self.delegate newsViewControllerDidFinish:self];

你应该写:

[self DismissModalViewControllerAnimated:YES];

这应该可以解决你的问题问题。我不认为编写额外的委托有什么意义,当您可以让视图控制器自行解散时,它们通常不会给您带来任何优势(在像这样的场景中)。

Try this:

- (IBAction)showNews:(id)sender
{    
    NewsViewController *controller = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
}

And in the News View, instead of writing

[self.delegate newsViewControllerDidFinish:self];

you should write:

[self dismissModalViewControllerAnimated:YES];

That should solve your problem. I don't see much point in writing extra delegates, they don't usually give you any advantages (in scenarios like this one), when you can just have a view controller dismiss itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文