【发布时间】:2018-07-15 01:54:36
【问题描述】:
我已经在 UIAlertViewController 中实现了文本字段,但我想为该文本字段实现委托方法。
`UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Total Value" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[ok setEnabled:NO];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField)
{
textField.placeholder = @"TotalValue";
textField.enabled = YES;
[[alert textFields][0] delegate];
[NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidChangeNotification object:textField queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
{
textField.text.length >0 ? [ok setEnabled:YES]: [ok setEnabled:NO];
}];
[NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:textField queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
{
[self updateTotalValue:textField.text];
}];
}];
[alert addAction:ok];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancel];
[self.navigationController presentViewController:alert animated:YES completion:nil];`UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Total Value" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[ok setEnabled:NO];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField)
{
textField.placeholder = @"TotalValue";
textField.enabled = YES;
[[alert textFields][0] delegate];
[NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidChangeNotification object:textField queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
{
textField.text.length >0 ? [ok setEnabled:YES]: [ok setEnabled:NO];
}];
[NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:textField queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note)
{
[self updateTotalValue:textField.text];
}];
}];
[alert addAction:ok];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancel];
[self.navigationController presentViewController:alert animated:YES completion:nil];
ERoor:从不兼容的类型“ApprovalDetailsViewController *const __strong”分配给“id _Nullable”
在 addtextfieldconfiguration 中,我想做我的委托方法,但它会出现一些错误 请哪位能举个例子。
【问题讨论】:
-
“它会出现一些错误”是什么意思?有错误信息吗?那么请将它们添加到您的问题中
-
我会添加请检查
-
您是否已将 UITextFieldDelegate 导入到您的 viewController 中?
-
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) 通过这个我们显示文本字段数组知道我不知道如何为该文本字段提供委托方法
标签: ios objective-c iphone xcode uitextfield