2017-08-02 8 views
0

私は、いくつかのテキストフィールドがあり、選択後にユーザーが検索ボタンを押したときにドロップダウンするフォームを持っています。新しいtableviewcontrollerが開きます。このテーブルビューコントローラでは、サービスからデータを取り出す関数をロードします。データはしばらく時間がかかるので、今度は、データがテーブルビューに読み込まれたときにインジケータを使用していましたが、動作しません。それはあなたがロードまたはのプロセスの残りしようとすると、アニメーションを表示するのに役立ちますアクティビティインジケータがボタンで機能していない

[self startYourAnimation]; 
[self performSelector:@selector(loadCustomerRecords) withObject:nil afterDelay:0.3]; 

:私のコードは

-(void)loadCustomerRecords 

{ 

    _City = nil; 

    _Title=nil; 

    _Price=nil; 

    _LandArea=nil; 
    _Phone=nil; 
    _Image1=nil; 
    _location=nil; 
    _name=nil; 
    _email=nil; 
    _descrip=nil; 
    _type=nil; 
    _rooms=nil; 
    _washroom=nil; 
    _floor=nil; 
    _Id=nil; 
    _status=nil; 



    NSUserDefaults *string = [NSUserDefaults standardUserDefaults]; 

    NSString *string1 = [string stringForKey:@"country"]; 

    NSString *string2 = [string stringForKey:@"city"]; 

    NSString *string3 = [string stringForKey:@"proptype"]; 

    NSString *string4 = [string stringForKey:@"propstatus"]; 

    NSString *string5 = [string stringForKey:@"proparea"]; 

    NSString *string6 = [string stringForKey:@"area"]; 

    NSString *string7 = [string stringForKey:@"min"]; 

    NSString *string8 = [string stringForKey:@"max"]; 




    if ([string4 isEqualToString:@"Property Status"]) { 

     string4 = @""; 
    } 


    if ([string3 isEqualToString:@"Property Type"]) { 

     string3 = @""; 
    } 


    if([string5 isEqualToString:@"Property Area"]){ 

     string5 = @""; 


    } 
    else{ 

     //concatenating strings 
    NSString *strappend=[NSString stringWithFormat:@"%@ %@",string6,string5]; 

    string5 = strappend; 
    } 

    if ([string7 isEqualToString:@""] && [string8 isEqualToString:@""]) { 

     string7 = @""; 
     string8 = @""; 
    } 


    NSLog(@"AREA : %@", string5); 


    NSLog(@"country %@",string1); 

    NSLog(@"city %@",string2); 

    NSLog(@"property_type %@",string3); 

    NSLog(@"propertystatus %@",string4); 

    NSLog(@"propertyarea %@",string5); 

    NSLog(@"area %@",string6); 

    NSLog(@"min %@",string7); 

    NSLog(@"max %@",string8); 


    CustomTableViewCell *check=[[CustomTableViewCell alloc]init]; 

    check.indicator.hidden=NO; 

    [check.indicator startAnimating]; 

    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration 

defaultSessionConfiguration]; 

    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: 

defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; 

    NSString *[email protected]"My URL"; 


    NSURL * url = [NSURL URLWithString:urlLinkA]; 

    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url]; 


    NSString *parameters = [NSString 

stringWithFormat:@"country=%@&city=%@&propertytype=%@&propertstatus=%@&propertyare 

a=%@",string1,string2,string3,string4,string5]; 

    NSLog(@"parameter %@",parameters); 

    [urlRequest setHTTPMethod:@"POST"]; 

    [urlRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLSessionDataTask * dataTask =[defaultSession 

dataTaskWithRequest:urlRequest 
                 completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
                  [check.indicator stopAnimating]; 

                  NSLog(@"Response:%@ %@\n", response, error); 
                  if(error == nil) 
                  { 



                   NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; 

                   NSLog(@"MY Response %@ ", dictionary); 

                   NSArray *results = [dictionary objectForKey:@"property_data"]; 
                   NSLog(@"RESULT %@ ", results); 




                   _City = [NSMutableArray array]; 
                   _Phone = [NSMutableArray array]; 
                   _LandArea = [NSMutableArray array]; 
                   _location = [NSMutableArray array]; 
                   _name = [NSMutableArray array]; 
                   _email = [NSMutableArray array]; 
                   _descrip = [NSMutableArray array]; 
                   _type = [NSMutableArray array]; 
                   _rooms = [NSMutableArray array]; 
                   _washroom = [NSMutableArray array]; 
                   _floor = [NSMutableArray array]; 
                   _Id = [NSMutableArray array]; 
                   _Price = [NSMutableArray array]; 
                   _Title = [NSMutableArray array]; 

                   for (NSDictionary * oneCustomer in results) 
                   { 
                    // Create a new Customer record 

                    StringData * newCustomer = [[StringData alloc] init]; 



                    newCustomer.title1 = [oneCustomer objectForKey:@"property_title"]; 
                    NSLog(@"ID: %@ ", newCustomer.title1); 
                    newCustomer.Area = [oneCustomer objectForKey:@"land_area"]; 
                    NSLog(@"Country: %@ ", newCustomer.Area); 
                    newCustomer.images = [oneCustomer objectForKey:@"images"]; 

                    NSLog(@"IMAGE: %@ ", newCustomer.images); 

                    newCustomer.City = [oneCustomer objectForKey:@"city"]; 
                    NSLog(@"CITY: %@ ", newCustomer.City); 

                    newCustomer.phoneno = [oneCustomer objectForKey:@"dealer_phone"]; 
                    NSLog(@"ID: %@ ", newCustomer.phoneno); 

                    newCustomer.location = [oneCustomer objectForKey:@"location"]; 
                    NSLog(@"ID: %@ ", newCustomer.location); 

                    newCustomer.property_description = [oneCustomer objectForKey:@"property_description"]; 
                    NSLog(@"ID: %@ ", newCustomer.property_description); 

                    newCustomer.property_type = [oneCustomer objectForKey:@"property_type"]; 
                    NSLog(@"ID: %@ ", newCustomer.property_type); 

                    newCustomer.property_id = [oneCustomer objectForKey:@"property_id"]; 
                    NSLog(@"ID: %@ ", newCustomer.property_id); 

                    newCustomer.status_property = [oneCustomer objectForKey:@"status_property"]; 
                    NSLog(@"ID: %@ ", newCustomer.status_property); 

                    newCustomer.status = [oneCustomer objectForKey:@"status"]; 
                    NSLog(@"ID: %@ ", newCustomer.status); 

                    newCustomer.dealer_email = [oneCustomer objectForKey:@"dealer_email"]; 
                    NSLog(@"ID: %@ ", newCustomer.phoneno); 

                    newCustomer.dealer_name = [oneCustomer objectForKey:@"dealer_name"]; 
                    NSLog(@"ID: %@ ", newCustomer.dealer_name); 

                    newCustomer.bath = [oneCustomer objectForKey:@"bathrooms"]; 
                    NSLog(@"ID: %@ ", newCustomer.bath); 

                    newCustomer.rooms = [oneCustomer objectForKey:@"rooms"]; 
                    NSLog(@"ID: %@ ", newCustomer.rooms); 

                    newCustomer.floors = [oneCustomer objectForKey:@"floors"]; 
                    NSLog(@"ID: %@ ", newCustomer.floors); 

                    newCustomer.country = [oneCustomer objectForKey:@"country"]; 
                    NSLog(@"ID: %@ ", newCustomer.country); 

                    newCustomer.Price = [oneCustomer objectForKey:@"price"]; 
                    NSLog(@"ID: %@ ", newCustomer.Price); 

                    // Add our new Customer record to our NSMutableArray 
                    [_Title addObject:newCustomer]; 


                    NSString *imageURL = @"http://www.pk.house/frontend/propertyimages/"; 


                    NSString *string3 = [imageURL stringByAppendingString:newCustomer.images]; 

                    newCustomer.images = string3; 

                    NSLog(@"Image URL %@",string3); 


                    // addObject:[oneCustomer objectForKey:@"property_title"]]; 
                    // NSLog(@"TET %@",_Title); 


                    [_Price addObject:[oneCustomer objectForKey:@"price"]]; 
                    NSLog(@"TET %@",_Price); 

                    [_Image1 addObject:[oneCustomer objectForKey:@"images"]]; 
                    NSLog(@"TET %@",_Image1); 

                    [_City addObject:[oneCustomer objectForKey:@"city"]]; 
                    NSLog(@"TET %@",_City); 

                    [_Phone addObject:[oneCustomer objectForKey:@"dealer_phone"]]; 
                    NSLog(@"TET %@",_Phone); 

                    [_name addObject:[oneCustomer objectForKey:@"dealer_name"]]; 
                    NSLog(@"TET %@",_name); 

                    [_email addObject:[oneCustomer objectForKey:@"dealer_email"]]; 
                    NSLog(@"TET %@",_email); 

                    [_rooms addObject:[oneCustomer objectForKey:@"rooms"]]; 
                    NSLog(@"TET %@",_rooms); 

                    [_washroom addObject:[oneCustomer objectForKey:@"bathrooms"]]; 
                    NSLog(@"TET %@",_washroom); 

                    [_floor addObject:[oneCustomer objectForKey:@"floors"]]; 
                    NSLog(@"TET %@",_floor); 

                    [_type addObject:[oneCustomer objectForKey:@"price"]]; 
                    NSLog(@"TET %@",_type); 

                    [_descrip addObject:[oneCustomer objectForKey:@"property_description"]]; 
                    NSLog(@"TET %@",_descrip); 

                    [_LandArea addObject:[oneCustomer objectForKey:@"land_area"]]; 
                    NSLog(@"TET %@",_LandArea); 

                    [_Id addObject:[oneCustomer objectForKey:@"property_id"]]; 
                    NSLog(@"TET %@",_Id); 


                    [_location addObject:[oneCustomer objectForKey:@"location"]]; 
                    NSLog(@"TET %@",_location); 

                                   } 
                   dispatch_async(dispatch_get_main_queue(), ^{ 
                    // This code will run once the JSON-loading section above has completed. 


                    [self.tableView reloadData]; 
                   }); 




                   NSString *status=[dictionary valueForKey:@"property_data"]; 
                   NSLog(@"Status:%@",status); 

                                 } 
                  else{ 
                   NSLog(@"network error:"); 


                  } 

                 }]; 
    [dataTask resume]; 


} 
+0

問題の関連コードを親切に貼り付けてください。 –

+0

完全なコードを投稿しないでください。ちょうどあなたのコードの一部が投稿していないと思っています –

+0

実際に私が書いた関数はviewdidload関数でロードされています。今、私はこれで、またはこれの前にインシケータの開始アニメーションを書くかどうかを尋ねています。 @ TusharSharma –

答えて

0

あなたは、コードの下に使用することができますthis-

dispatch_async(dispatch_get_main_queue(), ^{ 
     // This block will be executed asynchronously on the main thread. 
      [check.indicator stopAnimating]; 
     }); 
+0

ここから私はstarAnimationすべきですか? @Abhishek Jain –

+0

loadCustomerRecords関数の開始直後に開始できます。 –

+0

も機能の後で動作しません。 @Abhishek Jain –

0

を試してみてください、ですもの。

+0

どこよりも終わりますか? @Nirmalsinh –

+0

loadCustomerメソッドで停止できます。 – Nirmalsinh

+0

大丈夫です。 @Nirmalsinh –

関連する問題