简体   繁体   English

向toolbarItems添加UIButtonTypeDetailDisclosure导致运行时错误

[英]Addition of UIButtonTypeDetailDisclosure to toolbarItems causing runtime error

I am trying to add a UIButtonTypeDetailDisclosure to the bottom bar of my view. 我正在尝试将UIButtonTypeDetailDisclosure添加到我视图的底部栏。

The app is building successfully but at runtime I'm getting error below: 该应用程序正在成功构建,但在运行时我收到以下错误:

*** 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)

Find my code below: 找到我的代码如下:

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];

Toolbar items must be instances of UIBarButtonItem objects. 工具栏项必须是UIBarButtonItem对象的实例。 You are trying to add a UIButton instance. 您正在尝试添加UIButton实例。

The solution is to wrap the UIButton in a UIBarButtonItem . 解决方案是将UIButton包装在UIBarButtonItem

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM