Advertisement
Guest User

GridView

a guest
Sep 22nd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void)goToGridView
  2. {
  3.     int k1,j1;
  4.     int i = 0, j = 0,k = 0;
  5.     int x = 7;
  6.     int y = 0,count = 0;
  7.     int totalSubViews = [[self.scrlImages subviews] count];
  8. //            NSLog(@"totalSubViews:=%d",totalSubViews);
  9.     if (totalSubViews != 0)
  10.     {
  11.         for (k1=0,j1=0; k1 < totalSubViews; k1++ )
  12.         {
  13.             if ([[[self.scrlImages subviews] objectAtIndex:j1] isKindOfClass:[UIActivityIndicatorView class]])
  14.             {
  15.                 UIActivityIndicatorView *thisLabel = [[self.scrlImages subviews] objectAtIndex:j1];
  16.                 [thisLabel removeFromSuperview];
  17.                 thisLabel = nil;
  18.                 [thisLabel release];
  19.             }
  20.             else if ([[[self.scrlImages subviews] objectAtIndex:j1] isKindOfClass:[UIImageView class]])
  21.             {
  22.                 UIImageView *imgView = [[self.scrlImages subviews] objectAtIndex:j1];
  23.                 [imgView removeFromSuperview];
  24.                 imgView = nil;
  25.                 [imgView release];
  26.             }
  27.             else if ([[[self.scrlImages subviews] objectAtIndex:j1] isKindOfClass:[EGOImageButton class]])
  28.             {
  29.                 EGOImageButton *lbl = [[self.scrlImages subviews] objectAtIndex:j1];
  30.                 [lbl removeFromSuperview];
  31.                 lbl = nil;
  32.                 [lbl release];
  33.             }
  34.             else if ([[[self.scrlImages subviews] objectAtIndex:j1] isKindOfClass:[UILabel class]])
  35.             {
  36.                 UILabel *lbl = [[self.scrlImages subviews] objectAtIndex:j1];
  37.                 [lbl removeFromSuperview];
  38.                 lbl = nil;
  39.                 [lbl release];
  40.             }
  41.             else if([[[self.scrlImages subviews] objectAtIndex:j1] isKindOfClass:[UIButton class]])
  42.             {
  43.                 UIButton *thisButton = [[self.scrlImages subviews] objectAtIndex:j1];
  44.                 [thisButton removeFromSuperview];
  45.             }
  46.             else
  47.                 j1++;
  48.         }
  49.     }
  50.         NSMutableArray *sectionItems;
  51.             count = [arrPlaces count];
  52.         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  53.         for (i = 1; i<= count ; i++) //[arr count]
  54.         {
  55.                 sectionItems = [sections objectAtIndex:i-1];
  56.  
  57.             int tag = 1;
  58.             if (i > count ) break;
  59.            
  60.             UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(x + 58, y + 3,200,38)] ;
  61.             headerLabel.tag = [[NSString stringWithFormat:@"7%d",i] intValue];
  62.             headerLabel.backgroundColor = [UIColor clearColor];
  63.  
  64.                 headerLabel.text = [NSString stringWithFormat:@"%@",[arrPlaces objectAtIndex:i-1]];
  65.            
  66.             headerLabel.textAlignment = UITextAlignmentCenter;
  67.             headerLabel.font = [UIFont fontWithName:@"CALIBRI" size:17.5];
  68.             headerLabel.font = [UIFont boldSystemFontOfSize:17.5];
  69.             headerLabel.textColor = [UIColor whiteColor];
  70.            
  71.             UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(CountryLabel:)];
  72.             [headerLabel setUserInteractionEnabled:YES];
  73.             [headerLabel addGestureRecognizer:tap];
  74.             [tap release]; // if not using ARC
  75.            
  76.             [self.scrlImages addSubview:headerLabel];
  77.             y += 42;
  78.             for (j = 0; j< [sectionItems count]; j++)
  79.             {
  80.                 if (tag/2 >= [sectionItems count])  break;
  81.                 for (k = 0 ; k< 3; k++)
  82.                 {
  83.                     if (tag/2 >= [sectionItems count])  break;
  84.                     Item *item;
  85.                     if (tag >= 2)
  86.                     {
  87.                         item = [sectionItems objectAtIndex:tag/2 ];
  88.                     }
  89.                     else
  90.                     {
  91.                         item = [sectionItems objectAtIndex:tag - 1];
  92.                     }
  93.                    
  94.                     NSURL *imgURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",item.image_url]];
  95.                    
  96.                     UIImageView *imgBorder = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"border"]] autorelease];
  97.                     imgBorder.frame = CGRectMake(x = x, y = y, 97.3, 114.5);
  98.                     [self.scrlImages addSubview:imgBorder];
  99.                                        
  100.                     EGOImageButton *btnImage = [[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@""]] autorelease];
  101.                     [btnImage addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
  102.                     NSString *strTag = [NSString stringWithFormat:@"%d%d",i,tag];
  103.                     [btnImage setTag:[strTag intValue]];
  104.                     btnImage.frame = CGRectMake(x + 2.5, y + 3 , 92, 92);
  105.                    
  106.                     [btnImage performSelector:@selector(setImageURL:) withObject:imgURL afterDelay:2.0];
  107. //                    [btnImage performSelectorOnMainThread:@selector(setImageURL:) withObject:imgURL waitUntilDone:NO];
  108. //                    [btnImage performSelectorInBackground:@selector(setImageURL:) withObject:imgURL];
  109.                    
  110. //                    [btnImage setImageURL:imgURL];
  111.                     [self.scrlImages addSubview:btnImage];
  112.                    
  113.                     UILabel *lblCategory = [[UILabel alloc] initWithFrame:CGRectMake(x, y + 99.5, 97.3, 11)];
  114.                     lblCategory.textAlignment = UITextAlignmentCenter;
  115.                     lblCategory.textColor = [UIColor blackColor];
  116.                     lblCategory.backgroundColor = [UIColor clearColor];
  117.                     lblCategory.font = [UIFont fontWithName:@"CENTURY" size:10];
  118.                     lblCategory.text = [NSString stringWithFormat:@"%@",item.image_category];
  119.                     [self.scrlImages addSubview:lblCategory];
  120.                    
  121.                     tag++;
  122.  
  123.                     tag++;
  124.                     x = x + 104.3;
  125.                     [lblCategory release];
  126.                 }
  127.                 x = 7;
  128.                 y = y + 122.5;
  129.             }y = y - 9;
  130.             [headerLabel release];
  131.         }
  132.         [HUD hide:YES];
  133.         [pool release];
  134.        
  135.         if (y <= 331)
  136.         {
  137.             self.scrlImages.contentSize = CGSizeMake(320, y + 220);
  138.         }
  139.         else
  140.         {
  141.             self.scrlImages.contentSize = CGSizeMake(320, y + 15);
  142.         }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement