添加导致错误的 UIBarButtonItem 数组
Adding an array of UIBarButtonItem resulting in an Error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArrayI isSystemItem]:
unrecognized selector sent to instance 0x7fa5bbd726f0'
我已经关注了他的solution here,显然我没有任何缺陷。我正在做的是 - 在导航栏的右侧添加两个按钮(栏按钮)。
UIBarButtonItem *notificationButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Notification.png"]
style:UIBarButtonItemStylePlain target:self action:@selector(notificationAction)];
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search"]
style:UIBarButtonItemStylePlain target:self action:@selector(searchAction)];
NSArray *arrNavigationButtons = [NSArray arrayWithObjects:notificationButtonItem,searchButtonItem, nil];
// warning here - Incompatible pointer type.
self.navigationItem.rightBarButtonItem = arrNavigationButtons;
将最后一行更改为 rightBarButtonItems
。注意末尾的 s。
self.navigationItem.rightBarButtonItem 是单个 ButtonItem 并且您正在将 NSArray 传递给它,这是无效调用。要传递 NavigationBarButtons,您需要调用正确的函数。如果你调用它,我认为你会收到不兼容指针类型的警告。只需将您的代码更改为:
self.navigationItem.rightBarButtonItems = arrNavigationButtons;
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isSystemItem]: unrecognized selector sent to instance 0x7fa5bbd726f0'
我已经关注了他的solution here,显然我没有任何缺陷。我正在做的是 - 在导航栏的右侧添加两个按钮(栏按钮)。
UIBarButtonItem *notificationButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Notification.png"]
style:UIBarButtonItemStylePlain target:self action:@selector(notificationAction)];
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search"]
style:UIBarButtonItemStylePlain target:self action:@selector(searchAction)];
NSArray *arrNavigationButtons = [NSArray arrayWithObjects:notificationButtonItem,searchButtonItem, nil];
// warning here - Incompatible pointer type.
self.navigationItem.rightBarButtonItem = arrNavigationButtons;
将最后一行更改为 rightBarButtonItems
。注意末尾的 s。
self.navigationItem.rightBarButtonItem 是单个 ButtonItem 并且您正在将 NSArray 传递给它,这是无效调用。要传递 NavigationBarButtons,您需要调用正确的函数。如果你调用它,我认为你会收到不兼容指针类型的警告。只需将您的代码更改为:
self.navigationItem.rightBarButtonItems = arrNavigationButtons;