2013-12-10 29 views
0

我做了一個UIAlertView的子類。它實現了兩個UIAlertViewDelegate方法:alertView:clickedButtonAtIndex:在預期時調用,但alertViewShouldEnableFirstOtherButton:從不調用。UIAlertView子類中的alertViewShouldEnableFirstOtherButton不叫

看了一下相關的帖子,並補充說:

[textField sendActionsForControlEvents:UIControlEventEditingChanged]; 

,但沒有結果。我似乎沒有選擇。我在這裏錯過了什麼?

@implementation MyAlertView 

+ (MyAlertView*)showAlertForJson:(NSDictionary*)json delegate:(id<F2WebAlertDelegate>)delegate 
{ 
    MyAlertView* view = [[MyAlertView alloc] initWithJson:json delegate:delegate]; 

    return view; 
} 


- (instancetype)initWithJson:(NSDictionary*)json delegate:(id<MyWebAlertDelegate>)delegate 
{ 
    if (self = [super initWithTitle:json[@"title"] 
          message:json[@"message"] 
          delegate:self 
        cancelButtonTitle:json[@"cancelTitle"] 
        otherButtonTitles:nil]) 
    { 
     _json   = json; 
     self.webDelegate = delegate; 

     for (NSString* title in json[@"otherTitles"]) 
     { 
      [self addButtonWithTitle:title]; 
     } 

     [self initInput:json[@"input"]]; 

     [self show]; 
    } 

    return self; 
} 


- (void)initInput:(NSDictionary*)json 
{ 
    if (json == nil) 
    { 
     return; 
    } 

    [json[@"style"] isEqualToString:@"plain"]  ? self.alertViewStyle = UIAlertViewStylePlainTextInput  : 0; 
    ... 

    [self initTextField:[self textFieldAtIndex:0] withJson:json[@"field0"]]; 
    if (self.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) 
    { 
     [self initTextField:[self textFieldAtIndex:1] withJson:json[@"field1"]]; 
    } 
} 


- (void)initTextField:(UITextField*)textField withJson:(NSDictionary*)json 
{ 
    [textField sendActionsForControlEvents:UIControlEventEditingChanged]; 

    if (textField == nil || json == nil) 
    { 
     return; 
    } 

    [json[@"keyboard"] isEqualToString:@"ascii"]  ? (textField.keyboardType = UIKeyboardTypeASCIICapable)   : 0; 
    ... 
} 


#pragma mark - Alert View Delegate 

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    ... 
} 


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

@end 
+0

你正在運行哪個操作系統版本? – nkongara

+0

模擬器7.0上的@nkongara iOS 7。 –

回答

2

事實證明,作爲委託方法的名稱建議,您必須指定一個列表otherButtonTitlesUIAlertViewinitWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:

所以,隨後添加的按鈕addButtonWithTitle:不計算在內。

+1

這是一個錯誤,請將其歸檔。 –

相關問題