2012-08-23 172 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