开发者

UIAlertView not responding to UIAlertViewDelegate

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)_show开发者_Python百科PurchaseConfirmation {
    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


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.


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


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

 %new
 -(void) alertView:...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜