gpt4 book ai didi

ios - 自定义 View 中的 Crasher 作为 UINavigationControllers navigationItem.titleView

转载 作者:行者123 更新时间:2023-11-28 19:22:42 25 4
gpt4 key购买 nike

我有一个 UIViewController,它的 View 属性中有几个 subview (UISearchbar 和几个 UIButton)。 UIButton 连接到典型的 IBAction,例如 -(IBAction)buttonPressed:(id)sender for the UIControlEventTouchUpInside 状态 - 无论我是在 IB 中还是以编程方式执行都没有关系。

- (void)viewDidLoad {
MUZTitleViewController *title = [[MUZTitleViewController alloc]
initWithNibName:nil bundle:nil];
self.navigationItem.titleView = title.view;
}

在我的项目中还有一个UINavigationController。当我将 UINavigationBarnavigationItem.titleView 设置为我的 UIViewController View 时,我一点击就收到 EXC_BAD_ACCESS 异常其中一个按钮。我不知道这是为什么。

我上传了一个小示例项目来说明我的问题:Test010.xcodeproj (它启用了 ARC)

越来越多的我得出结论,使用 UIViewController 的 View 并将其分配给 titleView 不是一个好主意,但我没有看到任何在这里选择。

编辑: 抱歉,示例项目注释掉了导致异常的调用。我重新上传了链接的项目文件。

编辑^2:正如 PengOne 指出的那样,我已经跳过了我收到的确切错误消息:

2011-09-10 23:09:50.621 Test010[78639:f803] -[CALayer buttonPressed:]: unrecognized selector sent to instance 0x9254ae0
2011-09-10 23:09:50.623 Test010[78639:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer buttonPressed:]: unrecognized selector sent to instance 0x9254ae0'

最佳答案

您是否尝试过将 NSZombieEnabled 设置为 YES?如果我这样做,控制台会显示以下输出:

2011-09-10 22:56:23.329 Test010[6481:ef03] *** -[MUZTitleViewController
performSelector:withObject:withObject:]: message sent to deallocated
instance 0x7a7ff70

由于项目启用了 ARC, Controller 似乎在这一行之后的某个时间被释放:

MUZTitleViewController *title = [[MUZTitleViewController alloc] initWithNibName:nil bundle:nil];

我不确定最好的解决方案是什么,但是属性肯定有助于防止这样的异常:

// MUZDetailViewController.h
@property (strong, nonatomic) MUZTitleViewController *title;

// MUZDetailViewController.m
@synthesize title;

self.title = [[MUZTitleViewController alloc] initWithNibName:nil bundle:nil];
self.navigationItem.titleView = title.view;

关于ios - 自定义 View 中的 Crasher 作为 UINavigationControllers navigationItem.titleView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7374629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com