如何在nsobject类中调用UIAlertView?

时间:2015-03-05 03:56:52

标签: objective-c

在nsobject类中调用ui警报视图时遇到问题。我想知道我是否遗漏了什么。我得到

cannot find protocol definition "UIAlertViewDelegate"

提前致谢..

mynsobjectclass.h

@interface mynsobjectclass : NSObject <UIAlertViewDelegate>


@property (atomic, copy) NSString *serverURL
@end

mynsobjectclass.m

+(void)displayalert{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Hello there..." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
    [alert show];


}

1 个答案:

答案 0 :(得分:2)

现在不推荐使用UIAlertView UIAlertController应该从iOS 8开始使用。如果您的目标是iOS 7或更低版​​本,UIAlertViewDelegate不能是NSObject的委托。它必须是UIView / UIViewController的委托,因为它们需要显示警报