2013-11-20 69 views
4

我在觀察我的應用程序中的一個奇怪趨勢:每當顯示警告消息時,導航欄按鈕標題的值將更改爲其故事板標題值。這裏是UIAlertView中之一:上述UIAlertView導致更改導航欄按鈕的標題標籤

navigation bar button title getting changed by alert view

名稱值100,其在圖像中可見的是,存在於我的故事板的值。我成功地改變這個欄按鈕的價值,無論是當前的分數與該行:直到我顯示一些警報視圖

self.coinsRemainingButton.titleLabel.text = self.coinsRemaining; 

,一切工作正常。只要顯示任何UIAlertView,該導航欄按鈕的標題就會變爲100,而不考慮當前得分。例如。即使我當前的分數是500,只要出現警告消息,我的酒吧按鈕的值就會變爲100,如上面的屏幕截圖所示。
我已經仔細檢查過,我沒有錯誤地改變自己的價值。
如果我刪除UIAlertView行,一切都會按順序返回。
謝謝你的時間。

更新1:這是我的UIAlertView中代碼:

UIAlertView *iapSuccessful = [[UIAlertView alloc] initWithTitle:@"Purchase Successful" 
                  message:@"Congrats!! You just got coins" 
                  delegate:Nil 
                cancelButtonTitle:@"Ok" 
                otherButtonTitles: nil]; 
[iapSuccessful show]; 

更新2:我無法找到解決方案,因此,瞭解解決方案的緣故,我想通過代碼來更新我的欄按鈕標題顯示UIAlertView中後,立即:

[iapSuccessful show]; 
self.coinsRemainingButton.titleLabel.text = self.coinsRemaining; 

但UIAlertView仍然強制將欄按鈕的標題更改爲故事板的值。

+0

顯示在您使用方法uialertview – Ilario

+0

@Iriorio方法相當大,但我添加了用於警報視圖的UIAlertView代碼。 –

+0

我想看看添加點的那一塊,我想這是在UIAlertView – Ilario

回答

2

我嘗試了多種技巧來解決這個問題,但只要任何UIAlertView顯示欄按鈕項目,價值(titleLabel.text)被改爲它的故事板價值。

我觀察到值正在變化只有爲從故事板繪製的導航欄對象。所以我從情節提要刪除欄按鈕項目,並以編程方式添加欄按鈕,它解決了我的問題 :)
下面是添加欄按鈕項目編程,如果您需要代碼:

//Add a custom button as the right bar button item of navigation bar 
self.coinsRemainingButton.frame = CGRectMake(0.00f, 0.00f, 72.00f, 37.00f); 
[self.coinsRemainingButton setBackgroundImage:[UIImage imageNamed:@"coinsBackground"] forState:UIControlStateNormal]; 
[self.coinsRemainingButton setTitle:@"100" forState:UIControlStateNormal]; 
UIBarButtonItem *rightCustomBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.coinsRemainingButton]; 
self.navigationItem.rightBarButtonItem = rightCustomBarButtonItem; 
0

去除故事板按鈕的名稱,它解決了問題

+0

我試圖從故事板中刪除按鈕的標題,但當我運行我的應用程序時,按鈕的標題顯示爲空白。硬幣得到正確更新,但它們在GUI上不可見,標題只是空白。 'self.coinsRemainingButton.titleLabel.text = self.coinsRemaining;'似乎不工作,如果故事板標題是空的:( –

+0

哦..奇怪的事情...在viewDidLoad聲明多少應該這個textLabel? – Ilario

+0

沒什麼是在viewDidLoad屬於酒吧按鈕標題。似乎UIAlertView重置導航欄按鈕項。或至少重置酒吧按鈕標題的值爲其故事板的價值。我試着谷歌搜索,但沒有結果... –