0

我正在尝试将 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];
4

1 回答 1

2

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

解决方案是UIButtonUIBarButtonItem.

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

self.toolbarItems = @[ space, item, space ];
于 2013-11-14T05:16:05.327 回答