alertView:clickedButtonAtIndex:未调用。调用其他委托方法

时间:2015-01-08 09:21:06

标签: ios objective-c cocoa-touch uikit uialertview

这真的很奇怪。我从未见过这样的事情。我在UIViewController类别方法中显示提醒视图:

  UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];

for(NSString *buttonTitle in otherButtonTitles){
    [alertView addButtonWithTitle:buttonTitle];
}
objc_setAssociatedObject(self, &kVCActionHandleAlertCancelBlockKey, cancelBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
objc_setAssociatedObject(self, &kVCActionHandleAlertOtherBlockKey, otherBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
[alertView show];

永远不会调用-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

但是其他委托方法- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

成功调用

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex!有没有搞错?你见过这样的东西吗?

1 个答案:

答案 0 :(得分:0)

原因是我已经在我的视图控制器类中定义了-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex,但是期望在类别中使用相同的方法来触发。所以我认为结论是永远不要在类别中提供委托方法。这可能很危险