Ios 响应类别中的UIAlertViewDelegate
我有一个像这样的简单类 h m 现在我已经创建了这个类的不同扩展,我在这个类中导入并使用这些扩展 h 除了从未调用UIAlertViewDelegate方法之外,这一切都很好。 甚至可以从类别中响应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被
谢谢您的代码有错误。它是如何编译的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