我已成立了兩個名字警報視圖像這樣處理「確定」按鈕,從UIAlertView中
的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];
}
}
從我讀過這應該工作。但是,當我按下「確定」按鈕時,沒有任何反應。
嗯......我不能接受12分鐘的答案設置委託給自己太大。謝謝! – joshft91 2013-04-10 03:56:11
從alertView方法中的兩個字段獲取文本的最佳方式是什麼? – joshft91 2013-04-10 04:09:35
@ joshft91你可以分配標籤到文本框,然後從標籤獲取文本框和它的值。 – 2013-04-10 04:27:06