iphone - 多按钮、多 View 的相同 UIalertview

标签 iphone ios uialertview

在我的应用程序中,我有 4 个 UI 按钮。单击显示相同警报 View 的每个按钮都包含学习和播放选项,同时单击警报 View ,想要显示不同的 View 取决于 uibutton 的选择。这里是我的警报 View 代码。请帮助我对点击选项执行不同的 View 。

-(IBAction)animals
{
UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];     
[alert1 show];
}
-(IBAction)birds
{
UIAlertView *alert2=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];
[alert2 show];    
}
-(IBAction)direct
{ 
UIAlertView *alert3=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];
[alert3 show];
}
-(IBAction)fruit
{
UIAlertView *alert4=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];
[alert4 show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];

if ([buttonTitle isEqualToString:@"LEARN"]) 
{


    animallearn *aview=[[animallearn alloc]initWithNibName:@"animallearn" bundle:nil];
    [self.navigationController pushViewController:aview animated:YES];
}
else if([buttonTitle isEqualToString:@"PLAY"])
{ 
    birdslearn *bview=[[birdslearn alloc]initWithNibName:@"birdslearn" bundle:nil];
    [self.navigationController pushViewController:bview animated:YES];
 }
else
{
    return;
}
}

最佳答案

-(IBAction)animals
{
    UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];     
    alert1.tag = 1;  
    [alert1 show];
}
-(IBAction)birds
{
    UIAlertView *alert2=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"LEARN",@"PLAY",@"CANCEL",nil];
    alert2.tag = 2;  
    [alert2 show];    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];

    if(alertView.tag == 1)
    {
            //animal alert
    }
    else if(alertView.tag == 2)
    {
            //birds alert
    }
    // and so on......
}

关于iphone - 多按钮、多 View 的相同 UIalertview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12856203/

相关文章:

iphone - 自定义 Facebook 好友选择器?

ios - 当用户开始在键盘上打字时如何获取字符键码?

ios - 可达性 + UIAlertView + 误报

ios - 如何识别 ImageView 中不同位置的不同操作?

ios - 执行方法的顺序

ios - 为什么 Swift 闭包变量类型不能隐式解包可选值?

iphone - IOS 6 中的引用错误

iphone - objective-c : Do I have to retype all the code everytime?

ios - 如何将 StatusBar 样式更新为自定义转换的一部分

iphone - 在 facebook ios 上上传图片