gpt4 book ai didi

ios - 将 UIButtonTypeDetailDisclosure 添加到 toolbarItems 导致运行时错误

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

我正在尝试将 UIButtonTypeDetailDisclosure 添加到 View 的底部栏。

应用程序构建成功,但在运行时出现以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton view]: unrecognized selector sent to instance 0x17dafa00'
*** First throw call stack:
(0x30c1be83 0x3af786c7 0x30c1f7b7 0x30c1e0af... ... 0x3b471ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

在下面找到我的代码:

self.navigationController.toolbarHidden = NO;

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIButton *_appInfoContactButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[_appInfoContactButton addTarget:self action:@selector(bottomButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

self.toolbarItems = @[space, _appInfoContactButton, space];

最佳答案

工具栏项必须是 UIBarButtonItem 对象的实例。您正在尝试添加一个 UIButton 实例。

解决方案是将 UIButton 包装在 UIBarButtonItem 中。

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_appInfoContactButton];

self.toolbarItems = @[ space, item, space ];

关于ios - 将 UIButtonTypeDetailDisclosure 添加到 toolbarItems 导致运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19970034/

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