Iphone UIAlertView在数据上传之后而不是开始之前出现

Iphone UIAlertView在数据上传之后而不是开始之前出现,iphone,uialertview,uiactivityindicatorview,Iphone,Uialertview,Uiactivityindicatorview,我正在显示活动视图,但它仅在数据上载到服务器后显示,这可能是由于主线程停止。在上载数据时是否有任何方法显示此活动。两者同时存在 -(IBAction)startSyncButtonAction{ UIAlertView* alert= [[UIAlertView alloc] initWithTitle:@"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:

我正在显示活动视图,但它仅在数据上载到服务器后显示,这可能是由于主线程停止。在上载数据时是否有任何方法显示此活动。两者同时存在

  -(IBAction)startSyncButtonAction{


UIAlertView* alert= [[UIAlertView alloc] initWithTitle:@"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];

CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

for (int i=0; i<[appDelegate.coffeeArray count]; i++) {

Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];


    int mycount=[appDelegate.coffeeArray count];
    NSLog(@"My Array count is %d",mycount);


NSString*device_Id=coffeeObj.device_Id;
NSString*R1=coffeeObj.R1;
NSString*R2=coffeeObj.R2;
NSString*R3=coffeeObj.R3;
NSString*R4=coffeeObj.R4;
NSString*R5=coffeeObj.R5;
NSString*R6=coffeeObj.R6;
NSString*R7=coffeeObj.R7;
NSString*R8=coffeeObj.R8;
NSString*R9=coffeeObj.R9;
NSString*R10=coffeeObj.R10;
NSString*R11=coffeeObj.R11;
NSString*R12=coffeeObj.R12;
NSString*R13=coffeeObj.R13;
NSString*R14=coffeeObj.R14;     


NSString*update_date_time=coffeeObj.update_date_time;

    NSString*teritory1=coffeeObj.teritory;



    int mycount1=[appDelegate.coffeeArray count];


    NSLog(@"My Array After delete is %d",mycount1);


    NSLog(@"device_Id%@",device_Id);
    NSLog(@"R1%@",R1);
    NSLog(@"R2%@",R2);
    NSLog(@"R3%@",R3);
    NSLog(@"R4%@",R4);
    NSLog(@"R4%@",R5);
    NSLog(@"R4%@",R6);
    NSLog(@"R4%@",R7);
    NSLog(@"R4%@",R8);
    NSLog(@"R4%@",R9);
    NSLog(@"R4%@",R10);
    NSLog(@"R4%@",R11);
    NSLog(@"R4%@",R12);
    NSLog(@"R4%@",R13);
    NSLog(@"R4%@",R14);

    NSLog(@"update_date_time%@",update_date_time);

    NSString *post =[[NSString alloc] initWithFormat:@"device_Id=%@&R1=%@&R2=%@&R3=%@&R4=%@&R5=%@&R6=%@&R7=%@&R8=%@&R9=%@&R10=%@&R11=%@&R12=%@&R13=%@&R14=%@&update_date_time=%@&teritory1=%@",device_Id,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,update_date_time,teritory1];



    NSLog(post);
    NSURL *url=[NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];



    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",data);

      }


for (int i=0; i<[appDelegate.coffeeArray count]; i++) {

    Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];


     [appDelegate removeCoffee:coffeeObj];

}




[alert dismissWithClickedButtonIndex:0 animated:YES];

    }
-(iAction)启动syncbuttonAction{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“正在加载\n请等待…”消息:nil委托:自取消按钮:nil其他按钮:nil];
[警报显示];
UIActivityIndicatorView*指示器=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center=CGPointMake(150100);
[指示器启动激活];
[警报添加子视图:指示器];
CereniaAppDelegate*appDelegate=(CereniaAppDelegate*)[[UIApplication sharedApplication]委托];

对于(int i=0;i您可以将警报和上载代码放在主线程上,因此,当在另一个线程上打开对上载方法的警报调用(比如(void)uploadData)时。您的代码只是停留在UI上,直到完成所有数据的上载,然后UI就可以自由地进行警报

在操作-(iAction)startSyncButtonAction中,调用警报和UI内容:

UIAlertView* alert= [[UIAlertView alloc] initWithTitle:@"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];

CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];

for (int i=0; i<[appDelegate.coffeeArray count]; i++) {

Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];


    int mycount=[appDelegate.coffeeArray count];
    NSLog(@"My Array count is %d",mycount);


NSString*device_Id=coffeeObj.device_Id;
NSString*R1=coffeeObj.R1;
NSString*R2=coffeeObj.R2;
NSString*R3=coffeeObj.R3;
NSString*R4=coffeeObj.R4;
NSString*R5=coffeeObj.R5;
NSString*R6=coffeeObj.R6;
NSString*R7=coffeeObj.R7;
NSString*R8=coffeeObj.R8;
NSString*R9=coffeeObj.R9;
NSString*R10=coffeeObj.R10;
NSString*R11=coffeeObj.R11;
NSString*R12=coffeeObj.R12;
NSString*R13=coffeeObj.R13;
NSString*R14=coffeeObj.R14;     


NSString*update_date_time=coffeeObj.update_date_time;

    NSString*teritory1=coffeeObj.teritory;



    int mycount1=[appDelegate.coffeeArray count];


    NSLog(@"My Array After delete is %d",mycount1);


    NSLog(@"device_Id%@",device_Id);
    NSLog(@"R1%@",R1);
    NSLog(@"R2%@",R2);
    NSLog(@"R3%@",R3);
    NSLog(@"R4%@",R4);
    NSLog(@"R4%@",R5);
    NSLog(@"R4%@",R6);
    NSLog(@"R4%@",R7);
    NSLog(@"R4%@",R8);
    NSLog(@"R4%@",R9);
    NSLog(@"R4%@",R10);
    NSLog(@"R4%@",R11);
    NSLog(@"R4%@",R12);
    NSLog(@"R4%@",R13);
    NSLog(@"R4%@",R14);

    NSLog(@"update_date_time%@",update_date_time);
那么你需要另一种方法

   -(void) uploadData:(id) obj 
{
 NSLog(post);
    NSURL *url=[NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];



    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",data);

      }


for (int i=0; i<[appDelegate.coffeeArray count]; i++) {

    Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];


     [appDelegate removeCoffee:coffeeObj];
[self performSelectorOnMainThread:@selector(dataDoneLoading:) withObject:_photos waitUntilDone:NO];
}
-(void)上传数据:(id)obj
{
NSLog(职位);
NSURL*url=[NSURL URLWithString:@”http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
NSData*postData=[post数据使用编码:NSASCIIStringEncoding allowLossyConversion:是];
NSString*postLength=[NSString stringWithFormat:@“%d”,[postData长度]];
NSMutableURLRequest*请求=[[NSMutableURLRequest alloc]init];
[请求设置url:url];
[请求设置HttpMethod:@“POST”];
[请求设置值:HttpHeaderField的postLength:@“内容长度”];
[请求设置值:@“应用程序/x-www-form-urlencoded”forHTTPHeaderField:@“内容类型”];
[请求setHTTPBody:postData];
n错误*错误;
NSURLResponse*响应;
NSData*urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&响应错误:&错误];
NSString*data=[[NSString alloc]initWithData:urlData编码:NSUTF8StringEncoding];
NSLog(@“%@”,数据);
}
对于(int i=0;i使用

[自执行选择器:@selector(displayAlertView),对象:nil afterDelay:0.1]


方法。

你在警报或活动方面有问题吗?它们都是相同的活动显示在警报视图上如何做你能帮我解释一下保持应用程序的流吗?我将如何添加应用程序的流它们在其他按钮上单击此按钮会使事情变得不完美[self-performSelectorOnMainThread:@selector(dataDoneLoading:)withObject:nil waitUntilDone:NO];回到主线程,我想你可以在DataDoneLoad中放一个nnslog,看看它是OKNASAutoReleaseNoPool():类的对象0x61796c0 u NSCFDictionary autoreleased,没有池在适当的位置-就像这样泄漏显示
   -(void) uploadData:(id) obj 
{
 NSLog(post);
    NSURL *url=[NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];



    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",data);

      }


for (int i=0; i<[appDelegate.coffeeArray count]; i++) {

    Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];


     [appDelegate removeCoffee:coffeeObj];
[self performSelectorOnMainThread:@selector(dataDoneLoading:) withObject:_photos waitUntilDone:NO];
}