2010-12-20 97 views
1

我尝试在导航栏中添加“添加按钮”,但创建的按钮是一个没有文字的矩形按钮,不是“+”按钮,为什么?在导航栏中添加一个“+”按钮

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonSystemItemAdd target:self action:@selector(ajouterItem)]; 

self.navigationItem.rightBarButtonItem = addButton; 

[addButton release]; 
+0

听起来不可思议,你可以张贴截图? – 2010-12-20 01:47:57

回答

4

您正在将初始化工具与标题/样式的初始化工具混合在一起。你想这种形式:

- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action

这样称呼它:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(ajouterItem)];