UIAlertView 按钮如何调用另一个函数?

发布于 2024-11-19 01:11:12 字数 1546 浏览 7 评论 0原文

 -(void)buPressed{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Game Over"
                                                        message:@"YOU LOST! ALL YOUR BASE ARE BELONG TO US!"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Publish", nil];

    [alertView show];
    [alertView release];

    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex==0){
        NSLog(@"%d",buttonIndex);

    }
    else{
        [self bPressed];
    }   

    }

    -(void)bPressed{

    ModalViewConroller *yeniSayfa=[[ModalViewConroller alloc] init];

    yeniSayfa.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

    [self presentModalViewController:yeniSayfa animated:YES];

    [yeniSayfa release];

    //Restore to Defaults
    [button_1 setSelected:NO];
    [button_2 setSelected:NO];
    [button_3 setSelected:NO];
    [button_4 setSelected:NO];
    [button_5 setSelected:NO];
    [button_6 setSelected:NO];
    slider.value=50.00;
    UIImage *image = [UIImage imageNamed:@"Smiley_00025.png"];
    imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(81, 43, image.size.width, image.size.height);  
    [self.view addSubview:imageView];


    }

这是我的代码,我想让发布按钮调用 bPressed 函数,但它发出警告,并且当我触摸发布按钮时程序崩溃我想在按下发布按钮时打开模态视图有人可以帮助我吗?

 -(void)buPressed{

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Game Over"
                                                        message:@"YOU LOST! ALL YOUR BASE ARE BELONG TO US!"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Publish", nil];

    [alertView show];
    [alertView release];

    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex==0){
        NSLog(@"%d",buttonIndex);

    }
    else{
        [self bPressed];
    }   

    }

    -(void)bPressed{

    ModalViewConroller *yeniSayfa=[[ModalViewConroller alloc] init];

    yeniSayfa.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

    [self presentModalViewController:yeniSayfa animated:YES];

    [yeniSayfa release];

    //Restore to Defaults
    [button_1 setSelected:NO];
    [button_2 setSelected:NO];
    [button_3 setSelected:NO];
    [button_4 setSelected:NO];
    [button_5 setSelected:NO];
    [button_6 setSelected:NO];
    slider.value=50.00;
    UIImage *image = [UIImage imageNamed:@"Smiley_00025.png"];
    imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(81, 43, image.size.width, image.size.height);  
    [self.view addSubview:imageView];


    }

This is my code i want to make the publish button to call bPressed function but it is giving a warning and the program crashes when i touch the publish button i want to open a modalview when i push the publish button can anybody help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您需要在头文件中声明该函数,以便其他对象(在本例中是 UIAlertView 的实例,因为它的委托设置为您的类)知道该方法存在。

因此,在您的whatever_class.h 文件中,在@interface{ } 下面添加以下行:

-(void)bPressed;

You need to declare the function in your header file so that other objects (in this case an instance of UIAlertView, since its delegate is set to your class) know that this method exists.

So, in your whatever_class.h file, add the following line below the @interface{ }:

-(void)bPressed;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文