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

时间:2013-11-14 05:10:52

标签: ios uibutton navigationcontroller uibuttonbaritem toolbaritems

我正在尝试将UIButtonTypeDetailDisclosure添加到我视图的底栏。

该应用正在成功构建,但在运行时我收到以下错误:

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

1 个答案:

答案 0 :(得分:2)

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

解决方案是将UIButton包裹在UIBarButtonItem

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

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