Alertview与整数

时间:2013-09-10 11:04:20

标签: ios integer uialertview

大家好,我想提出一个关于alertview的想法。我正在考虑创建一个Uialertview,它将提示用户输入两个整数。然后我想检索这两个整数并将其放在一个计时器上,第二个放在一个sql语句中。因此,如果有人可以帮助如何实现,我会apreciate它。谢谢大家。

这是我的代码,直到现在

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"info" message:@"Set time For The Game." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];
    alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
NSLog(@"Entered: %@", [[alertView textFieldAtIndex:0] text]);
    [alertView show];

2 个答案:

答案 0 :(得分:0)

您需要使用UIAlterView的委托方法。

首先让“自我为代表”而非“无代表”。

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"info" message:@"Set time For The Game." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];

将此功能添加到您的班级:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UITextField *field = [alertView textFieldAtIndex:0];
    NSLog(@"%@", field.text);
}

要100%正确,请在您实现此协议的标题类信息中添加。

答案 1 :(得分:0)

//试试这个

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"info" message:@"Set time For The Game." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];
alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
[alertView textFieldAtIndex:0].delegate = self;
[alertView show];


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   NSLog(@"Entered: %@", [[alertView textFieldAtIndex:0]text]);
}