2015-01-22 2 views
0

У меня есть проблемаUICollectionViewFlowLayout позиция

Когда я нажимаю tabcontoller uıcollectionviewflowlayout положение меняется :(

Следующий код не работает

- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated]; 


    UICollectionViewFlowLayout *collectionViewLayout = (UICollectionViewFlowLayout*)self.myCollectionView.collectionViewLayout; 

    collectionViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); 
} 

Перед изображением:

http://i.hizliresim.com/O3zA8P.png

Когда я нажимаю tabcontoller после изображения:

http://i.hizliresim.com/12ZvBb.png

пожалуйста, помогите мне

другое изображение загрузить

http://i.hizliresim.com/LYRnZG.png

+0

Какая ошибка? первый или второй? – iOSNoob

+0

неправильный второй. первое изображение истинно –

+0

См. мой обновленный ответ. – iOSNoob

ответ

0

обновление: Удалить

UICollectionViewFlowLayout *collectionViewLayout = (UICollectionViewFlowLayout*)self.myCollectionView.collectionViewLayout; 
collectionViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); 

от viewWillAppear и вернуть его в viewDidLoad.

+0

У меня есть коллекцияview внутри uiview. Когда я нажимаю tabcontoller, ячейка в списке просмотра коллекции изменяется: (или изменение позиции ячейки приблизительно 20 пикселей. –

+0

вы проверили мой обновленный ответ и выполнили его? – iOSNoob

+0

Этот код не работал –

0
 - (void)viewDidLoad 
    { 
     [self.myCollectionView registerNib:[UINib nibWithNibName:PhotoCellIdentifier bundle:[NSBundle mainBundle]] 
       forCellWithReuseIdentifier:PhotoCellIdentifier];   
     self.myCollectionView.delegate=self; 
     self.myCollectionView.dataSource=self; 
[self.myCollectionView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];  
     [self yukle]; 
    } 

     -(void) storkontrol:(NSArray*)skulist{ 

     [[RMStore defaultStore] requestProducts:[NSSet setWithArray:skulist] success:^(NSArray *products, NSArray *invalidProductIdentifiers) { 

      if (products.count ==0) 
      { 
       self.eserList = nil; 

       [self sitedeveriyokbilgi]; 




      } else 

      { 

       NSMutableArray *ll = [[NSMutableArray alloc] init]; 

       int i =0; 

       // satın alışverişte alınan ürünelr geliyor 

       // NSLog(@"RMStore dan ürünler bekleniyor.."); 

       for (SKProduct*urun in products) { 

        // NSLog(@"ürün : %@",urun.productIdentifier); 

        for (EserFiles*eser in self.eserList) { 

         if ([urun.productIdentifier isEqualToString:eser.eser.eserstokkod]) 
         { 
          eser.eser.product = urun; 
          [ll insertObject:eser atIndex:i]; 
          i++; 


         } 
        } 

       } 


       //   NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@"eser.esersayi" ascending:NO selector:@selector(compare:)]; 
       //   [ll sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]]; 

       self.eserList = ll; 



       // [HesapViewController setEserListVitrin: ll]; 

       // [AyarlarViewController setEserListVitrin: ll]; 

       [global setEserListVitrin: ll]; 



       // NSLog(@"RMStore dan ürün çekme işlemi bitti"); 



       [self.myCollectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 

       _productsRequestFinished = YES; 




       [spinnerorta stopAnimating]; 


      } 




     } failure:^(NSError *error) { 
      [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

      [spinnerorta stopAnimating]; 

      NSLog(@"failure:^(NSError *error urunlist %@",error.localizedDescription); 
     }]; 


    } 

     -(void)sitedeveriyokbilgi{ 

     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 270)]; 
     label.backgroundColor = [UIColor clearColor]; 
     label.textAlignment = NSTextAlignmentCenter; 
     label.textColor = [UIColor grayColor]; 
     label.numberOfLines = 0; 

     label.text = @"Listelenecek eser bulunamadı"; 


     [self.view addSubview:label]; 

     NSLog(@"Listelenecek eser bulunamadı"); 

     [spinnerorta stopAnimating]; 


    } 

     -(void)yukle{ 



     spinnerorta = [[UIActivityIndicatorView alloc] 
         initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     spinnerorta.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin; 
     spinnerorta.center = self.view.center; 

     [spinnerorta startAnimating]; 

     [self.view addSubview: spinnerorta]; 


     //eğer kategoriden geliyorsa hiç bir zamanön bellekleme olmayacak 

     __block NSArray *arry ; 
     NSMutableArray *skulist = [[NSMutableArray alloc] init]; 

     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 

     //ana sayfa ise 
     if (self.gelenviewid==1) 
     { 

      if ([[global getEserList] count] ==0) 
      { 

       // NSLog(@"yeni liste alınıyor......."); 
       NSMutableArray *skulist = [[NSMutableArray alloc] init]; 

       JSONLoader *jsonLoader = [[JSONLoader alloc] init]; 

       arry = [jsonLoader locationsFromJSONFile]; 


      } else{ 


       self.eserList =[global getEserList]; 




       // NSLog(@"ön bellekten doldu...."); 


       [self.myCollectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 



       // [spinnerorta stopAnimating]; 

       return ; 

      } 




     } else if(self.gelenviewid==2) 
     { 


      arry = [JSONLoader getEserlerToKategory:self.catId]; 



     } 



      if ([arry count] >0) 
      { 

       self.eserList = arry; 



       for (EserFiles*eserfile in self.eserList) { 


        // NSLog(@"sayı :%d %@",eserfile.eser.esersayi,eserfile.eser.kisaisim); 

        [skulist addObject:eserfile.eser.eserstokkod]; 
       } 

       // dispatch_async(dispatch_get_main_queue(), 
       //     ^{ 


       [self storkontrol:skulist]; 




       // }); 

      } else { 



      dispatch_async(dispatch_get_main_queue(),^{ 


       [spinnerorta stopAnimating]; 
       [self sitedeveriyokbilgi]; 

      }); 



      } 



     }); 



    } 

     -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
     return 1; 
    } 

    - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { 

     int count = self.eserList.count; 

     return count; 
    } 

     - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
         cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 


     // [collectionView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; 



     EserFiles *esefiles =[self.eserList objectAtIndex:indexPath.row]; 

     Eser *eser = esefiles.eser; 


     UrunCell *urunCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UrunCell" forIndexPath:indexPath]; 



     UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] 
              initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     spinner.frame = CGRectMake((urunCell.frame.size.width-25)/2, 50, 24, 24); 
     [spinner startAnimating]; 


     [urunCell.contentView addSubview: spinner]; 




     NSString *title = @""; 

     if ([eser.kisaisim isKindOfClass:[NSNull class]] || [eser.kisaisim isEqualToString:@""]){ 

      title = eser.isim; 
     } else title = eser.kisaisim; 



     urunCell.UrunIsim.text=title; 


     // NSLog(@"title : %@",title); 



     [urunCell.UrunImage sd_setImageWithURL:[NSURL URLWithString:eser.kapakYol] 
          placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; 



     [spinner stopAnimating]; 


     return urunCell; 

    } 

     -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 

     self.vitrinDetayViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"VitrinDetayViewController"]; 

     EserFiles *esefiles =[self.eserList objectAtIndex:indexPath.row]; 

     self.vitrinDetayViewController.eser = esefiles; 



     [self.navigationController pushViewController:self.vitrinDetayViewController animated:YES]; 

    } 

     - (void)viewWillAppear:(BOOL)animated { 

     // [self.myCollectionView setContentOffset:CGPointZero animated:NO]; 
     [super viewWillAppear:animated]; 


     UICollectionViewFlowLayout *collectionViewLayout = (UICollectionViewFlowLayout*)self.myCollectionView.collectionViewLayout; 
     // collectionViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); 

     //[self.myCollectionView setContentOffset:CGPointZero animated:NO]; 

     // self.automaticallyAdjustsScrollViewInsets = NO; 
     [spinnerorta stopAnimating]; 

    } 
+0

Просмотреть сейчас Я обновил ваш код. Проверьте, работает ли это. Примите мой ответ, если он работает. – iOSNoob

+0

этот код не работает. возможно, проблема в коллекции scrool –

Смежные вопросы