2011-02-05 40 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:...