2013-12-10 2 views
0

Я создал подкласс UIAlertView. Он реализует два метода UIAlertViewDelegate: alertView:clickedButtonAtIndex: вызывается, когда ожидается, однако alertViewShouldEnableFirstOtherButton: никогда не вызывается.alertViewShouldEnableFirstOtherButton в подклассе UIAlertView не называется

Если бы взглянуть на соответствующих должностей и добавил:

[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

@ nkongara iOS 7 на Simulator 7.0. –

ответ

2

Оказывается, что, как и имя метода делегата предполагают, вы должны указать список otherButtonTitles к UIAlertView «s initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:.

Итак, кнопки, добавленные позже с addButtonWithTitle:, не учитываются.

+1

Какая ошибка, пожалуйста, зарегистрируйтесь. –

Смежные вопросы