UIAlertView 不响应 UIAlertViewDelegate

发布于 2024-10-15 22:22:19 字数 1230 浏览 7 评论 0原文

我正在使用 iPhone 的徽标(MobileSubstrate 插件),并为我的

@interface MyClass : NSObject

- (void)alertView:(UIAlertView *) 使用 .h 文件AlertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 0) {

位于 .m 中,但没有任何效果,当点击警报上的按钮时,它不会调用我为每个 ButtonIndex 设置的内容。

谢谢。

编辑:这就是我所拥有的;

#import "Tweak.h"

%hook ASApplicationPageHeaderView

- (void)_showPurchaseConfirmation {
    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"title"];
    [alert setMessage:@"message"];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"button 1"];
    [alert addButtonWithTitle:@"continue"];
    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {    
    if (buttonIndex == 0) {  //also tried (UIAlertView *)alertView
        UIAlertView *lol = [[UIAlertView alloc] init];
        [lol setTitle:@"button 1"];
        [lol setMessage:@"button 1"];
        [lol setDelegate:self];
        [lol addButtonWithTitle:@"lol"];
        [lol show];
        [lol release];
    } else {
        %orig;
    }
}

%end

I'm using logos for iPhone (MobileSubstrate addons), with a .h file for my

@interface MyClass : NSObject <UIAlertViewDelegate>

and the

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0) {

is in the .m, but nothing is working, when tapping the buttons on the alert, it doesn't invoke what I have set for each buttonIndex.

Thanks.

Edit: Here's what I've got;

#import "Tweak.h"

%hook ASApplicationPageHeaderView

- (void)_showPurchaseConfirmation {
    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"title"];
    [alert setMessage:@"message"];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"button 1"];
    [alert addButtonWithTitle:@"continue"];
    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {    
    if (buttonIndex == 0) {  //also tried (UIAlertView *)alertView
        UIAlertView *lol = [[UIAlertView alloc] init];
        [lol setTitle:@"button 1"];
        [lol setMessage:@"button 1"];
        [lol setDelegate:self];
        [lol addButtonWithTitle:@"lol"];
        [lol show];
        [lol release];
    } else {
        %orig;
    }
}

%end

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

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

发布评论

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

评论(3

相思碎 2024-10-22 22:22:19

您很可能需要在某个时候使用以下内容将您的类注册为委托

 [yourAlertViewObject setDelegate:self];

: /UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/doc/uid/TP40007548" rel="nofollow">UIAlertViewDelegate 协议参考 文档说(强调我的):

如果您添加自己的按钮或
自定义警报的行为
查看,实现符合要求的委托
到这个协议来处理
相应的委托消息。 使用
警报视图的委托属性
指定您的应用程序之一
对象作为委托。

You'll most likely need to register your class as the delegate at some point using something along the lines of:

 [yourAlertViewObject setDelegate:self];

As the UIAlertViewDelegate Protocol Reference docs say (emphasis mine):

If you add your own buttons or
customize the behavior of an alert
view, implement a delegate conforming
to this protocol to handle the
corresponding delegate messages. Use
the delegate property of an alert view
to specify one of your application
objects as the delegate.

西瓜 2024-10-22 22:22:19

在该类中定义您的警报并声明警报委托以希望它开始为您工作

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert View "
                      " 
                                                message:@"Would you like to do something?"
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"Button1", @"Button2", nil];
[alert show];
[alert release];

Define your alert within that class and declare the alert delegate to self hope it start working to you

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert View "
                      " 
                                                message:@"Would you like to do something?"
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"Button1", @"Button2", nil];
[alert show];
[alert release];
楠木可依 2024-10-22 22:22:19

您只需将 %new 放在 alertView 委托前面:

 %new
 -(void) alertView:...

You just need to put %new in front of the alertView delegate:

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