2011-02-05 74 views
2

我使用标识为iPhone(MobileSubstrate有插件),与.h文件我UIAlertView中没有响应UIAlertViewDelegate

@interface MyClass : NSObject <UIAlertViewDelegate>

- (void)alertView:(UIAlertView *)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 

回答

4

你很可能需要使用的东西线沿线的注册类为在某一时刻委托:

[yourAlertViewObject setDelegate:self]; 

由于UIAlertViewDelegate Protocol Reference文档说(重点煤矿):

如果您添加自己的按钮或 自定义警报 视图的行为,请将符合 的代理实现为此协议以h和 相应的委托消息。 使用 警报视图的委托属性 可将您的应用程序 对象中的一个指定为委托。

+0

更多信息&无耻的插件:http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c/626946 – 2011-02-05 15:04:38

+0

我试着设置警报的委托自我和零,没有任何作品。 – Mitochondria 2011-02-05 15:17:00

1

这个类中定义的警报并宣布告警授人以自我希望它开始工作到您

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]; 
+0

如上所述,我试过自己和零,似乎没有任何工作。 – Mitochondria 2011-02-06 00:32:52

1

你只需要把%newalertView代表的面前:

%new 
-(void) alertView:...