2013-10-10 33 views
0

我有一個簡單的視圖,用「showAlert」方法鏈接了一個按鈕。當我點擊這個按鈕時,它顯示一個UIAlertView。如何使用ios 7禁用UIAlertView按鈕?

之前,與iOS 6,我用下面的代碼來禁用一個UIAlertView中按鈕:

- (IBAction)showAlert:(id)sender 
{ 
    myAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"Retour" otherButtonTitles:@"Button1", @"Button2", @"Button3", @"Button4", nil]; 
    [myAlert show]; 

    for(UIView *aView in myAlert.subviews) 
    { 
     if ([[[aView class] description] isEqualToString:@"UIAlertButton"]) 
     { 
      UIButton *aButton = (UIButton *)aView; 
      if ([aButton.titleLabel.text isEqualToString:@"Button2"]) 
       aButton.enabled = NO; 
     } 
    } 
} 

現在,與iOS 7,這是行不通的,爲什麼?

回答

1

由於iOS7無法添加或操作子視圖或UIAlertView,您需要創建自己的對不起。

子類UIView創建您自己的UIAlertView或使用第三方庫。

+0

pfff ...爲什麼會出現這種迴歸?感謝您快速回答安東尼奧。 –

+0

煩人,我知道! –

+0

是的,討厭...感謝您的幫助。 –

0

添加子視圖UIAlertView不能從iOS的7

唯一的辦法是去自定義UIView子類可以作爲UIAlertView行動。

Githubthis答案可能會給你一個解決方案。

+0

謝謝。非常無聊...... –

0

可以使用委託方法

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView 
{ 
    return NO; 
} 

作品在IOS 7也禁用1日其他按鈕UIAlertView中

+0

感謝Viruss,但我需要能夠根據其名稱有時禁用第一個按鈕,有時第二個按鈕或其他一些按鈕。 –

+0

@Erzékiel:不,你只能用這種方法禁用第一個btn。 –

+0

@Virussmca我也想改變第一個按鈕的標題我該怎麼做,請建議一些可以在iOS 6上工作的東西,以及使用ios 7 – user100