2012-08-23 178 views
1

我不知道为什么下面的代码不工作:添加两个按钮rightBarButtonItems不工作

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStyleBordered target:self action:@selector(newClicked:)]; 

UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)]; 

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:newButton, shareButton, nil]; 

它只导航栏,而不是“shareButton”按钮,显示“newButton”的UIBarButtonItem。

+0

我只是复制并粘贴您的代码在我的应用程序,它的工作原理应该如此。 任何方式尝试通过重命名您的对象,例如newButton,shareButton –

+0

是不是'新'一个保留字? – igrek

+0

@igrek:只有在C++ – user102008

回答

1

看起来这个问题不得不做与代码质疑代码如下:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)]; 
label.backgroundColor = [UIColor clearColor]; 
label.font = [UIFont fontWithName:@"Marker Felt" size:26.0]; 
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; 
label.textAlignment = UITextAlignmentCenter; 
label.textColor =[UIColor whiteColor]; 
label.text=self.title; 
self.navigationItem.titleView = label; 
[label release]; 

万一别人遇到现在张贴这这个问题!

+1

你能解释一下这个问题是如何解决的? titleView与问题有关吗? – igrek

+0

我有同样的问题,试图解决,谢谢 – igrek

2

rightBarButtonItems是IOS 5 我认为这个问题是与客体名new,请将此更改为任何其他名称,如newButton或类似的东西。 由于新是用于memoryallocation关键字在C++

3

我发现涉及此行为的不同问题。

如果您已经设置了自定义titleViewnavigationItem.titleView = ...),那么导航项有时可以隐藏按钮,除非第一个按钮没有空间。

因此,请确保您限制您的自定义titleViewwidth