0

我想打电话didDismissWithButtonIndexUITextViewClass ,但没有打电话。我还实现UIAlertViewDelegateMyViewcontroller.h文件和[alert setDelegate:self]方法。

那么可以在Class中调用UIAlertViewDelegate 方法吗?UITextView

+ (void)deleteTextr:(UITapGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
    {
        UIAlertView *alert  = [[UIAlertView alloc]initWithTitle:@"" message:@"Delete Text !!!!" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"No", nil];
        [alert setDelegate:self];
        [alert show];
    }
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 1)
    {
        [self removeFromSuperview];
    }
}
4

2 回答 2

3

只需将委托方法更改为类方法。像这样:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;

// - 更改为 +

+ (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
于 2014-07-10T05:48:41.097 回答
2

deleteTextr:是一个类方法。在类方法的上下文中,self只是对类的引用。要使用 UIAlertViewDelegate 协议,您需要将类的实例分配给 UIAlertView 实例的委托属性,这只能在实例方法中完成。

阅读本文以更好地掌握上述概念。

于 2014-07-10T05:44:17.217 回答