Добавление UIButtonTypeDetailDisclosure к элементам панели инструментов, вызывающее ошибку времени выполнения
Я пытаюсь добавить 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 ответ
Решение
Элементы панели инструментов должны быть экземплярами UIBarButtonItem
объекты. Вы пытаетесь добавить UIButton
пример.
Решение состоит в том, чтобы обернуть UIButton
в UIBarButtonItem
,
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:_appInfoContactButton];
self.toolbarItems = @[ space, item, space ];