2011-08-30 53 views
6

我想創建一個UIAlertView有3個選項,沒有「取消」按鈕,但是當我這樣做時,它總是將「按鈕3」作爲取消按鈕。有什麼辦法可以避免這種情況?UIAlertView無取消按鈕?

UIAlertView *alertView= [[UIAlertView alloc] initWithTitle:@"Select One" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Button 1",@"Button 2", @"Button3", nil]; 
+0

從文檔看來,它看起來沒有什麼奇怪的方式。我仍在玩它,但似乎取消按鈕默認爲其他按鈕之一。 –

+0

在這一點上,我已經與一個行動表。不是我想要這樣做的方式,所以如果有人知道如何使警報視圖正常工作,請隨時留言。 – Chris

回答

6

This是一篇關於如何改變取消按鈕位置的文章。另外,如果你只有1中UIAlertView按鈕,然後設置:

_alertView.cancelButtonIndex = -1; 

將使該按鈕顯示爲不可撤銷型按鈕。據我所知,一旦你有超過1個按鈕,UIAlertView強制最後一個按鈕是取消按鈕。通過reference查看可能會爲您提供有關如何設置屬性來達到此目的的線索,但我不太確定。希望有助於!

7

我做了不同的事情,把cancelButtonTitle的參數作爲nil

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" 
          message:@"Message here" 
          delegate:self 
          cancelButtonTitle:nil 
          otherButtonTitles:@"OK", nil]; 
+0

爲什麼我的回答錯了? –