Question

I am trying to add a UIButtonTypeDetailDisclosure to the bottom bar of my view.

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];
Was it helpful?

Solution

Toolbar items must be instances of UIBarButtonItem objects. You are trying to add a UIButton instance.

The solution is to wrap the UIButton in a UIBarButtonItem.

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

self.toolbarItems = @[ space, item, space ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top