can';虽然我添加了show,但在iPhone中没有显示UIAlertView

can';虽然我添加了show,但在iPhone中没有显示UIAlertView,iphone,ios,ipad,uialertview,Iphone,Ios,Ipad,Uialertview,我编写此代码是为了定义UIAlertView -(void)showAlertMethod2 { progressAlert2 = [[UIAlertView alloc] initWithTitle:@"تتم المزامنة..يرجى الانتظار ...\n" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; CGRect alertFrame = progressAlert2.frame;

我编写此代码是为了定义
UIAlertView

-(void)showAlertMethod2 {
progressAlert2 = [[UIAlertView alloc] initWithTitle:@"تتم المزامنة..يرجى الانتظار ...\n" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
CGRect alertFrame = progressAlert2.frame;
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.frame = CGRectMake(135,alertFrame.size.height+55, alertFrame.size.width,30);
activityIndicator.hidden = NO;
activityIndicator.contentMode = UIViewContentModeCenter;
[activityIndicator startAnimating];
[progressAlert2 addSubview:activityIndicator];
[progressAlert2 show];
}

-(void)dismissAlertMethod2
{
[progressAlert2 dismissWithClickedButtonIndex:0 animated:YES];
}
我在这里打电话:

[NSThread detachNewThreadSelector:@selector(showAlertMethod2) toTarget:self withObject:nil];

[self performSelector:@selector(syncToServer) withObject:nil];
[self performSelector:@selector(syncFromServer) withObject:nil]

[NSThread detachNewThreadSelector:@selector(dismissAlertMethod2) toTarget:self withObject:nil];
syncToServer
是将数据同步到服务器的方法,
syncFromServer
是将数据同步到服务器的方法

问题是,
UIAlertView
没有显示,有人知道遗漏了什么吗? 提前谢谢

-(void)showAlertMethod2 {
    progressAlert2 = [[UIAlertView alloc] initWithTitle:@"تتم المزامنة..يرجى الانتظار ...\n" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    CGRect alertFrame = progressAlert2.frame;
    UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityIndicator.frame = CGRectMake(135,alertFrame.size.height+55,    alertFrame.size.width,30);
    activityIndicator.hidden = NO;
    activityIndicator.contentMode = UIViewContentModeCenter;
    [activityIndicator startAnimating];
    [progressAlert2 addSubview:activityIndicator];
    [progressAlert2 show];
}

-(void)dismissAlertMethod2
{
    [progressAlert2 dismissWithClickedButtonIndex:0 animated:YES];
}
这是你的方法很好

现在就这样称呼他们吧

-(void)syncBothWay{
    [self showAlertMethod2];
    [self performSelector:@selector(syncToServer) withObject:nil afterDelay:0.0];
    [self performSelector:@selector(syncFromServer) withObject:nil afterDelay:0.0];
}

-(void)syncToServer{
    //sync
}

-(void)syncFromServer{
    //sync
    after sync completed call [self dismissAlertMethod2];
}
这是你的方法很好

现在就这样称呼他们吧

-(void)syncBothWay{
    [self showAlertMethod2];
    [self performSelector:@selector(syncToServer) withObject:nil afterDelay:0.0];
    [self performSelector:@selector(syncFromServer) withObject:nil afterDelay:0.0];
}

-(void)syncToServer{
    //sync
}

-(void)syncFromServer{
    //sync
    after sync completed call [self dismissAlertMethod2];
}

我用下面的代码解决了这个问题

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self showAlertMethod2];
                });

                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncFromServer) withObject:nil];

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self dismissAlertMethod2];
                });

我用下面的代码解决了这个问题

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self showAlertMethod2];
                });

                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncToServer) withObject:nil];
                [self performSelector:@selector(syncFromServer) withObject:nil];

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self dismissAlertMethod2];
                });

您正在使用
NSThread detachNewThreadSelector:
显示
UIAlertView
解除
您的
UIAlertView
,问题是您现在有两个独立的
NSThreads
一个用于显示警报,另一个用于解除警报。因此,您无法确定哪个
线程将首先完成。因此,可能关闭UIAlertView的第二个线程首先完成,这将阻止
UIAlertView
显示

尝试调用
UIAlertView
,而不为每个方法创建新线程

[self showAlertMethod2];
[self dismissAlertMethod2];

您正在使用
NSThread detachNewThreadSelector:
显示
UIAlertView
解除
您的
UIAlertView
,问题是您现在有两个独立的
NSThreads
一个用于显示警报,另一个用于解除警报。因此,您无法确定哪个
线程将首先完成。因此,可能关闭UIAlertView的第二个线程首先完成,这将阻止
UIAlertView
显示

尝试调用
UIAlertView
,而不为每个方法创建新线程

[self showAlertMethod2];
[self dismissAlertMethod2];

从主线程调用showAlertMethod2。您可以通过示例代码向我演示如何修改UI吗?线程(与主线程不同)不应被允许修改UI…您可以解释如何修复此问题吗。在你的密码里,你的话对我来说还不够。您没有设置委托。您首先添加委托。从主线程调用showAlertMethod2。您可以通过示例代码向我演示如何进行操作吗?不允许线程(与主线程不同)修改UI…您可以解释如何修复此问题吗。在你的密码里,你的话对我来说还不够。您没有设置委托。首先添加委托。