在没有界面的类中,实现弹出UIAlertView || 在没有界面的类中,刷新程序界面 思路

+(DisplayErrorMsg *)sharedDisplayErrorMsg
{
    static DisplayErrorMsg *instance = nil;
    @synchronized(instance)
    {
        if (instance == nil) {
            instance = [[DisplayErrorMsg alloc] init];
        }
    }
    return instance;
}

-(void)showAlertView:(NSString *)title Message:(NSString *)msg
{
    NSArray *array = [NSArray arrayWithObjects:title,msg, nil];
    [self performSelectorOnMainThread:@selector(doAlert:) withObject:array waitUntilDone:NO];
}

//在没有界面的类中,实现弹出UIAlertView
-(void)doAlert:(NSArray *)array
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[array objectAtIndex:0] message:[array objectAtIndex:1] delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];

    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];   //获取界面的思路

    [delegate.window addSubview:alert];

    [alert show];
    [alert release];
 
}
原文地址:https://www.cnblogs.com/ygm900/p/3457274.html