我试图给我的 UIToolBar 一个标题,但是当我尝试添加一个带有 title 属性的 UIBarItem 时,我得到了这个错误。我的代码:
UIBarItem *title = [[UIBarItem alloc] init];
title.title = @"My Title";
[toolBar setItems:@[cancel, title, ok]];
我查看了 UIBarItem 的官方文档,它确实有一个完全有效的“title”属性。我在这里做错了什么?
最佳答案
我认为问题在于,UIBarItem
是 UIBarButtonItem
和 UITabBarItem
的抽象父类(super class)。
也许该方法只是在 header 中声明而未实现,或者抽象实现调用了-doesNotRecognizeSelector:
。
UIBarItem
is an abstract superclass for items added to a bar that appears at the bottom of the screen. …
对于 -[UIToolbar items]
或 UINavigationBar
-[UINavigationItem (left|right)BarButtonItems]
,你必须使用 UIBarButtonItem
。
关于ios - [UIBarItem setTitle :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15795595/