从UIAlertView文本框Objective-C提取输入
我在试图找到答案时太沮丧了,所以我将作为一个问题 如何从Objective-C中的UIAlertView文本框中获取原始文本 这是我的密码:从UIAlertView文本框Objective-C提取输入,objective-c,input,uialertview,Objective C,Input,Uialertview,我在试图找到答案时太沮丧了,所以我将作为一个问题 如何从Objective-C中的UIAlertView文本框中获取原始文本 这是我的密码: UIButton *AppCrashButton = [UIButton buttonWithType: UIButtonTypeCustom]; AppCrashButton.frame = CGRectMake(0, (self.view.frame.size.height - 44) / 6 * 1, self.view.frame.size.wid
UIButton *AppCrashButton = [UIButton buttonWithType: UIButtonTypeCustom];
AppCrashButton.frame = CGRectMake(0, (self.view.frame.size.height - 44) / 6 * 1, self.view.frame.size.width, (self.view.frame.size.height - 44) / 6);
[AppCrashButton setTitle: @"Ping" forState: UIControlStateNormal];
[AppCrashButton addTarget: self action: @selector(Click) forControlEvents: UIControlEventTouchUpInside];
AppCrashButton.backgroundColor = [UIColor colorWithRed:0.19 green:0.19 blue:0.19 alpha:1.0];
AppCrashButton.layer.borderColor = [UIColor colorWithRed:0.96 green:0.26 blue:0.21 alpha:1.0].CGColor;
AppCrashButton.layer.borderWidth = 0.5f;
[self.view addSubview: AppCrashButton];
-(void) Click {
UIAlertView *AppCrashAlert = [[UIAlertView alloc] initWithTitle: @"IP Ping" message: @"Please enter the IP address" delegate: self cancelButtonTitle: @"Cancel" otherButtonTitles: @"OK", nil];
AppCrashAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
[AppCrashAlert show];
[AppCrashAlert release];
}
它显示了一个自定义按钮,单击该按钮后,将执行“Click”方法,该方法将ping主机
我想知道如何从文本输入中获取文本
谢谢
要在UIAlertView文本字段中获取输入的文本,请将
UIAlertViewDelegate
委托给控制器
@interface YourViewController ()<UIAlertViewDelegate>
那么
我要把这个放在哪里?此外,是否可以对输入的文本发出警报,而不是对其进行
NSLog
ing?仅供参考-UIAlertView
早在iOS 8中就被弃用了。您应该使用UIAlertController
。
@interface YourViewController ()<UIAlertViewDelegate>
UIAlertView *AppCrashAlert = [[UIAlertView alloc] initWithTitle: @"IP Ping" message: @"Please enter the IP address" delegate: self cancelButtonTitle: @"Cancel" otherButtonTitles: @"OK", nil];
AppCrashAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
// Set delegate
AppCrashAlert.delegate = Self;
[AppCrashAlert show];
[AppCrashAlert release];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex(NSInteger)buttonIndex{
NSLog(@"Text : %@",[[alertView textFieldAtIndex:0] text]);
}