首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAlertView未响应UIAlertViewDelegate

UIAlertView未响应UIAlertViewDelegate
EN

Stack Overflow用户
提问于 2011-02-05 22:58:21
回答 3查看 2.9K关注 0票数 2

我正在使用iPhone (MobileSubstrate插件)的徽标,以及我的.h文件

@interface MyClass : NSObject <UIAlertViewDelegate>

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

谢谢。

编辑:这是我得到的;

代码语言:javascript
复制
#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
EN

回答 3

Stack Overflow用户

发布于 2011-02-05 23:03:36

在某些情况下,您很可能需要将您的类注册为委托,方法如下:

代码语言:javascript
复制
 [yourAlertViewObject setDelegate:self];

正如UIAlertViewDelegate Protocol Reference文档所说(强调我的):

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

票数 4
EN

Stack Overflow用户

发布于 2011-02-06 00:14:23

在该类中定义您的警报,并将警报委托声明为self,希望它开始对您起作用

代码语言:javascript
复制
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];
票数 1
EN

Stack Overflow用户

发布于 2013-04-01 06:12:13

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

代码语言:javascript
复制
 %new
 -(void) alertView:...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4907522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档