Advertisement
Guest User

Nested Push Issue

a guest
Sep 3rd, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Button 1
  2. - (IBAction)btnFavCol:(id)sender {
  3.     [self chkResponse];
  4. }
  5. -(void)chkResponse
  6. {
  7.     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  8.    
  9.     NSString *email = [defaults objectForKey:@"email"];
  10.     NSString *passWord = [defaults objectForKey:@"passWord"];
  11.     NSLog(@"user name is = %@ and password is = %@",email,passWord);
  12.  
  13.     NSString *parameterisedUrl = [NSString stringWithFormat:@"http://www.coloragon.com/ajax_svc.php?controller=fetchFavouratePalletColors&email=%@&password=%@",email,passWord];
  14.     NSURL *url = [NSURL URLWithString:parameterisedUrl];
  15.    
  16.     NSURLRequest *request = [NSURLRequest requestWithURL:url];
  17.     [NSURLConnection connectionWithRequest:request  delegate:self];
  18.     NSURLResponse *response;
  19.     NSError *error;
  20.     NSData * data = [NSURLConnection sendSynchronousRequest:request
  21.                                           returningResponse:&response
  22.                                                       error:&error];
  23.     if (!error) {
  24.         NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  25.        
  26.         NSLog(@"Login response: is %@",str);
  27.        
  28.     }
  29.     else{
  30.         NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  31.        
  32.         NSLog(@"Login response: is %@",str); //getting response
  33.         NSLog(@"I am here in else");
  34.     }
  35.    
  36.    
  37. }
  38.  
  39. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  40.     NSLog(@"ReceivedResponse");
  41.  
  42. }
  43.  
  44. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  45.     // [self.responseDATA appendData:data];
  46.     colorNamesArray = [[NSMutableArray alloc] init];
  47.     colorHexArray = [[NSMutableArray alloc] init];
  48.     paletteIDArray = [[NSMutableArray alloc] init];
  49.     NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  50.     NSLog(@"json data is %@",jsonData);
  51.     NSLog(@"object class == %@",[jsonData class]);
  52.     favColorsArray =[jsonData valueForKey:@"r"];
  53.     for(NSArray *tmpArr1 in favColorsArray){
  54.         if([tmpArr1 valueForKey:@"name"]){
  55.             colorName=[tmpArr1 valueForKeyPath:@"name"];
  56.             NSString *colorHex=[tmpArr1 valueForKeyPath:@"colors"];
  57.             NSString *paletteId = [tmpArr1 valueForKey:@"id"];
  58.             [paletteIDArray addObject:paletteId];
  59.             [colorNamesArray addObject:colorName];
  60.             [colorHexArray addObject:colorHex];
  61.         }
  62.        
  63.     }
  64.    
  65.     NSLog(@"color names array is %@",colorNamesArray);
  66.     NSLog(@"color hex array is %@",colorHexArray);
  67.    
  68.     NSUserDefaults *defaultFavColors = [NSUserDefaults standardUserDefaults];
  69.     [defaultFavColors setObject:colorNamesArray forKey:@"colorNamesArray"];
  70.     [defaultFavColors setObject:colorHexArray forKey:@"colorHexArray"];
  71.     [defaultFavColors setObject:paletteIDArray forKey:@"paletteIDArray"];
  72.     [defaultFavColors synchronize];
  73.     FavColorsViewController *favColVC = [[FavColorsViewController alloc] init];
  74.     [self.navigationController pushViewController:favColVC animated:YES];
  75.    
  76. }
  77.  
  78. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  79.     NSLog(@"didFailWithError");
  80.    
  81.     NSLog( [NSString stringWithFormat:@"Connection failed: %@", error],
  82.           [error description]);
  83. }
  84.  
  85. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  86.    
  87.     NSLog(@"connectionFinishLoading");
  88. }
  89.  
  90. Button 2
  91. - (IBAction)btnFavGallery:(id)sender {
  92.    
  93.     [self getGalleries];
  94.    
  95. }
  96. -(void)getGalleries
  97. {
  98.    
  99.     NSString *parameterisedUrl = [NSString stringWithFormat:@"http://www.coloragon.com/ajax_svc.php?controller=fetchGalleries&email=saad.khalid@digitalnet.com&password=12345"];
  100.    
  101.     NSURL *url = [NSURL URLWithString:parameterisedUrl];
  102.    
  103.     NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
  104.    
  105.    
  106.    
  107.    
  108.    
  109.     [theRequest setHTTPMethod:@"POST"];
  110.    
  111.    
  112.     [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  113.    
  114.    
  115.    
  116.    
  117.    
  118.     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  119.    
  120.     if(theConnection)
  121.        
  122.     {
  123.         //  NSLog(@"Connection Successful");
  124.        
  125.         NSURLResponse *response;
  126.        
  127.         NSError *err;
  128.        
  129.         NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
  130.        
  131.        
  132.        
  133.         NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:nil];
  134.    
  135.    
  136.  
  137.    NSMutableArray  *galleryNameArray = [[NSMutableArray alloc]init];
  138.    NSMutableArray  *galleryIDArray =  [[NSMutableArray alloc]init];
  139.        
  140.         NSLog(@"json data is %@",jsonData);
  141.         NSLog(@"object class == %@",[jsonData class]);
  142.       NSMutableArray *galleriesArray =[jsonData valueForKey:@"gals"];
  143.         for(NSArray *tmpArr1 in galleriesArray){
  144.             if([tmpArr1 valueForKey:@"name"]){
  145.                
  146.                 NSString *galleryName   = [tmpArr1 valueForKeyPath:@"name"];
  147.                 NSString *galID     = [tmpArr1 valueForKey:@"id"];
  148.                
  149.                 [galleryNameArray addObject:galleryName];
  150.                 [galleryIDArray addObject:galID];
  151.             }
  152.            
  153.         }
  154.         NSLog(@"gallery names are %@",galleryNameArray);
  155.         FavGalleriesViewController *favGalVC = [[FavGalleriesViewController alloc] init];
  156.         favGalVC.galleryIDArray = galleryIDArray;
  157.         favGalVC.galleryNameArray = galleryNameArray;
  158.         [self.navigationController pushViewController:favGalVC animated:YES];
  159.        
  160.     }
  161.    
  162.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement