我正在创建我的第一个iphone应用程序,但现在面临很多问题..我正在尝试使用一个警告窗口,其中包含是和否。当我点击它不会它应该保留在同一个屏幕上然而当我点击是的它应该带我到另一个屏幕,但我无法做到是的部分。我的代码看起来像这样..
-(IBAction)buttonPressedid)sender
{
NSString *TITLE = [[NSString alloc] initWithFormat: @"Do you want to add the ingredient to your Grocery list"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message"
message:TITLE
delegate:nil
cancelButtonTitle:@"No"
otherButtonTitles:@"YES",nil];
因此,当我点击是时,它应该带我到另一个屏幕。我该怎么做?
请帮忙......
答案 0 :(得分:2)
你需要UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
了解更多细节阅读以下教程
答案 1 :(得分:0)
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Game Over”消息:nil delegate:self cancelButtonTitle:@“Quit”otherButtonTitles:@“Restart”,nil]; alert.tag = 1; [警示显示]; [警告发布];
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag == 3){
if(buttonIndex == 0){
出口(0);
}
其他{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self viewWillAppear:YES];
[UIView commitAnimations];
appDelegate.winningAmount = nil;
encylCount = 0;
googleCount = 0;
mGoogleButton.userInteractionEnabled = YES;
mEncyclopediaButton.userInteractionEnabled = YES;
}
}
}