我为两个要输入的名称设置了一个警报视图,如下所示
UITextField *player1; UITextField *player2;
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Enter 2 player names"
message:@"\n\n\n" // IMPORTANT
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
player1 = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)];
[player1 setBackgroundColor:[UIColor whiteColor]];
[player1 setPlaceholder:@"player1"];
[prompt addSubview:player1];
player2 = [[UITextField alloc] initWithFrame:CGRectMake(12, 85, 260, 25)];
[player2 setBackgroundColor:[UIColor whiteColor]];
[player2 setPlaceholder:@"player2"];
[prompt addSubview:player2];
// set place
[prompt setTransform:CGAffineTransformMakeTranslation(0, 110)];
[prompt show];
//[prompt release];
// set cursor and show keyboard
[player1 becomeFirstResponder];
现在我想处理“确定”按钮的点击。我正在尝试做这样的事情没有运气..
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
NSLog(@"cancel");
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OK works" message:@"no error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
从我读过的内容来看,这应该可行。但是,当我按下“确定”按钮时,什么也没有发生。