iphone - UIAlertView 不响应 UIAlertViewDelegate

标签 iphone objective-c uialertview logos

我正在使用 iPhone 的 Logo (MobileSubstrate 插件),并为我的 .h 文件

@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

最佳答案

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

 [yourAlertViewObject setDelegate:self];

作为UIAlertViewDelegate Protocol Reference文档说(强调我的):

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.

关于iphone - UIAlertView 不响应 UIAlertViewDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4907522/

相关文章:

ios - Swift 中奇怪的导航栏/状态栏行为

ios - NSURLSessionDataTask 超时后续请求失败

ios - 如何在 iOS 中将 UITextView 插入 UIAlertview

iphone - nsxmlparser 中的点自记法

ios - 单击选项卡栏更多按钮时获取两个导航栏

objective-c - UITableView - 当滚动太快时,最后一个单元格的内容会替换第一个单元格

ios - UIAlertView 委托(delegate)给另一个类

iphone - UIAlertView问题

iphone - iPhone 应用程序中奇怪的 OpenGL ES 行为

objective-c - 如何计算 PDF 文档中嵌入图像的分辨率 (DPI)?