use*_*343 3 objective-c uialertview ios
似乎有东西丢失,但下面的代码正在生成nil的两个值title和title1(即使它正确启动正确的警报类型,并不表示任何警告或错误).这个实现的问题可能是什么UIAlertView?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"High Score" message:(NSString *)scoreMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.alertViewStyle= UIAlertViewStylePlainTextInput;
UITextField *title1 = [alert textFieldAtIndex:0];
[alert show];
title1= [alert textFieldAtIndex:0];
NSString *title = title1.text;
NSLog(@"The name is %@",title);
NSLog(@"Using the Textfield: %@",[[alert textFieldAtIndex:0] text]);
Run Code Online (Sandbox Code Playgroud)
RJR*_*RJR 11
在代码中的某处显示警报并从中设置视图控制器作为UIAlertView的委托呈现.然后实现委托以接收事件.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"High Score" message:@"Score Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.alertViewStyle= UIAlertViewStylePlainTextInput;
[alert show];
Run Code Online (Sandbox Code Playgroud)
实现委托方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
UITextField *textField = [alertView textFieldAtIndex:0];
NSString *title = textField.text;
NSLog(@"The name is %@",title);
NSLog(@"Using the Textfield: %@",[[alertView textFieldAtIndex:0] text]);
}
Run Code Online (Sandbox Code Playgroud)
[alert show]在用户可以在文本字段中输入任何文本之前立即返回.您需要通过设置和实施警报后解除警报后的文本(例如,还有其他几种可能性).delegatealertView:clickedButtonAtIndex:
| 归档时间: |
|
| 查看次数: |
5472 次 |
| 最近记录: |