iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – UIAlertViewStylePlainTextInput返回密钥委托大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在使用一个新的iOS 5功能的UIAlertView.我创建一个这样的UIAlertView: UIAlertView *scanCode = [[UIAlertView alloc] initWithtitle:NSLocalizedString(@"Some title", @"") message:nil delegate:self cancelButtontitle:@"Cancel"
@H_450_14@
@H_450_14@
我正在使用一个新的iOS 5功能的UIAlertView.我创建一个这样的UIAlertView:

UIAlertView *scanCode = [[UIAlertView alloc] initWithtitle:NSLocalizedString(@"Some title",@"") message:nil delegate:self cancelButtontitle:@"Cancel" otherButtontitles:NSLocalizedString(@"OK",@""),nil];
        [scanCode setAlertViewStyle:UIAlertViewStylePlaintexTinput];
        scanCode.tag = 1234;
        [scanCode show];
        [scanCode release];

我现在使用的代表是:

-(void)alertView:(UIAlertView *)alertView clickedButtonATindex:(NSInteger)buttonIndex {
    if (alertView.tag == 1234) {
        if (buttonIndex == 1)
        {
            //do something
            }
        }
    }
}

现在我想模拟输入键,所以当用户键盘上返回时,同样的事情发生在按下警报的确定按钮.我该怎么做?

提前致谢!

解决方法

确保你的类符合< UITextFieldDelegate>协议,使UIAlertView为您的类的属性,并添加以下行到您的设置代码

self.scanCode = [[UIAlertView alloc] initWithtitle:NSLocalizedString(@"Some title",nil];
[self.scanCode setAlertViewStyle:UIAlertViewStylePlaintexTinput];
self.scanCode.tag = 1234;
//add this...
[[self.scanCode textFieldATindex:0] setDelegate:self];
[self.scanCode show];

通过成为输入文本字段的代表,您可以了解按键盘上的返回键.然后在您的类的.m文件中,您将在下面实现委托方法,并告知警报消失:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.scanCode dismissWithClickedButtonIndex:self.scanCode.firstOtherButtonIndex animated:YES];
    return YES;
}
@H_450_14@

大佬总结

以上是大佬教程为你收集整理的iphone – UIAlertViewStylePlainTextInput返回密钥委托全部内容,希望文章能够帮你解决iphone – UIAlertViewStylePlainTextInput返回密钥委托所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:iphone委托密钥返回
猜你在找的iOS相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap