UIAlertView子类中的alertViewShouldEnableFirstOtherButton未调用 [英] alertViewShouldEnableFirstOtherButton in UIAlertView subclass not called
问题描述
我做了一个 UIAlertView
子类.它实现了两个 UIAlertViewDelegate
方法:在需要时调用 alertView:clickedButtonAtIndex:
,但是从不调用 alertViewShouldEnableFirstOtherButton:
.
I made a UIAlertView
subclass. It implements two UIAlertViewDelegate
methods: alertView:clickedButtonAtIndex:
is called when expected, however alertViewShouldEnableFirstOtherButton:
is never called.
看看相关文章并添加:
[textField sendActionsForControlEvents:UIControlEventEditingChanged];
,但没有结果.我似乎没有选择.我在这里想念什么?
but without results. I seem to be out of options. What am I missing here?
@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
推荐答案
结果表明,正如委托方法的名称所建议的那样,您必须为 UIAlertView
指定一个列表 otherButtonTitles
的 initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
.
Turns out that, as the delegate method's name suggest, you must specify a list otherButtonTitles
to UIAlertView
's initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
.
因此,以后使用 addButtonWithTitle:
添加的按钮不计算在内.
So, buttons added later with addButtonWithTitle:
do not count.
这篇关于UIAlertView子类中的alertViewShouldEnableFirstOtherButton未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!