Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 响应类别中的UIAlertViewDelegate_Ios_Objective C_Delegates_Uialertview_Objective C Category - Fatal编程技术网

Ios 响应类别中的UIAlertViewDelegate

Ios 响应类别中的UIAlertViewDelegate,ios,objective-c,delegates,uialertview,objective-c-category,Ios,Objective C,Delegates,Uialertview,Objective C Category,我有一个像这样的简单类 h m 现在我已经创建了这个类的不同扩展,我在这个类中导入并使用这些扩展 h 除了从未调用UIAlertViewDelegate方法之外,这一切都很好。 甚至可以从类别中响应UIAlertViewDelegate调用吗 谢谢您的代码有错误。它是如何编译的someFunction是一个在self上调用实例方法的类方法。好吧,将委托设置为调用委托的对象是没有意义的。你甚至在哪里声明你实现了这个协议?您可能应该子类,并考虑使用UiAltRead控件,因为UIAdvutVIEW被

我有一个像这样的简单类

h

m

现在我已经创建了这个类的不同扩展,我在这个类中导入并使用这些扩展

h

除了从未调用UIAlertViewDelegate方法之外,这一切都很好。 甚至可以从类别中响应UIAlertViewDelegate调用吗


谢谢

您的代码有错误。它是如何编译的someFunction是一个在self上调用实例方法的类方法。好吧,将委托设置为调用委托的对象是没有意义的。你甚至在哪里声明你实现了这个协议?您可能应该子类,并考虑使用UiAltRead控件,因为UIAdvutVIEW被弃用。错误的代码可能是在类方法中显示ActReVIEW,并将委托设置为不会触发UIAcReaveVIEW委托方法的类,这些方法都是实例方法,除非你创建了一个类的实例。我很抱歉。为了这个问题,我简化了我的代码。我在上面对其进行了编辑,以表明我确实在实例而不是类上调用了showAlert方法。此外,我正在尝试将其恢复到iOS 6,因此同时使用
UIAlertView
UIAlertController
。我想我已经找到了问题所在。一旦显示警报,我的UIAlert类别即被解除锁定。
@interface DJMyClass : NSObject
+ (void)someFunction;
@end
#import "DJJavaFunction+UIAlert.h"

@interface DJMyClass ()
@property (nonatomic, strong) NSString* someString;
@end
@implementation DJMyClass
+(void)functionWithName:(NSString *)functionName
                 callbackId:(int)callbackId
                       args:(NSArray *)args
{
    DJMyClass *newFunction = [[DJMyClass alloc] init];
    newFunction.function = functionName;
    newFunction.callbackId = callbackId;
    newFunction.args = args;

    [newFunction processFunction];
}
- (void)processFunction
{
  [self showAlertWithTitle:title message:message buttons:buttons inputField:inputField callbackId:_callbackId];
}
@end
@interface DJMyClass (UIAlert) <UIAlertViewDelegate>

- (void)showAlertWithTitle:(NSString *)title
                   message:(NSString *)message
                   buttons:(NSArray *)buttons
                inputField:(NSDictionary *)inputField
                callbackId:(int)callbackId;

@end
@implementation DJJavaFunction (UIAlert)

- (void)showAlertWithTitle:(NSString *)title
                   message:(NSString *)message
                   buttons:(NSArray *)buttons
                inputField:(NSDictionary *)inputField
                callbackId:(int)callbackId
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:nil];
        // Add the buttons
        for (NSString *btn in buttons)
        {
            [alert addButtonWithTitle:btn];
        }

        // Add text field
        if (!inputField)
        {
            alert.alertViewStyle = UIAlertViewStyleDefault;
        }
        else
        {
            alert.alertViewStyle = UIAlertViewStylePlainTextInput;

            UITextField *textField = [alert textFieldAtIndex:0];
            textField.placeholder = inputField[@"placeholder"];
            textField.text = inputField[@"text"];
        }

        alert.delegate = self;
        alert.tag = 44;
        [alert show];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

@end