Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  2. {
  3.  
  4. return [secCollectionImagesArray count];
  5.  
  6. NSLog(@"secCollectionimagesArray is:%@ ",secCollectionImagesArray);
  7.  
  8. }
  9. - (MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  10. {
  11. MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
  12. UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
  13. UILabel *descLabel = (UILabel *)[cell viewWithTag:110];
  14.  
  15. [descLabel setText:[secCollectionImagesArray objectAtIndex:indexPath.row]];
  16. recipeImageView.image = [UIImage imageNamed:[secCollectionImagesArray objectAtIndex:indexPath.row]];
  17.  
  18. int pages = floor(collectionView.contentSize.width / collectionView.frame.size.width) + 1;
  19. [pageControl setNumberOfPages:pages];
  20.  
  21. return cell;
  22. }
  23.  
  24. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  25.  
  26. third=[[thirdViewController alloc]initWithNibName:@"thirdViewController" bundle:nil];
  27.  
  28. third.recipeImagedname=[secCollectionImagesArray objectAtIndex:indexPath.row];
  29.  
  30. [self presentViewController:third animated:YES completion:nil];
  31.  
  32. }
  33. //write this in thirdViewController ViewDidLoad
  34. currentIndex=0;
  35.  
  36. eachImgView.image=[UIImage imageNamed:recipeImagedname];
  37.  
  38. alloc]initWithNibName:@"secondViewController" bundle:nil];
  39.  
  40. _second.secCollectionImagesArray=DataArray;
  41.  
  42. NSLog(@"dataArray:%@",DataArray);
  43.  
  44. UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
  45.  
  46. UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
  47. [swipeLeft setNumberOfTouchesRequired:1];
  48.  
  49. [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
  50.  
  51. [swipeRight setNumberOfTouchesRequired:1];
  52.  
  53. [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
  54. [self.eachImgView addGestureRecognizer:swipeLeft];
  55. [self.eachImgView addGestureRecognizer:swipeRight];
  56.  
  57.  
  58. }
  59. -(void)handleSwipe:(UISwipeGestureRecognizer*)sender
  60.  
  61. {
  62.  
  63. NSLog(@"swiped :");
  64.  
  65. NSLog(@"total item is %ld ",(long)DataArray.count);
  66.  
  67. NSInteger index = currentIndex;
  68.  
  69.  
  70. if (sender.direction == UISwipeGestureRecognizerDirectionLeft)
  71.  
  72. {
  73.  
  74. index++;
  75. }
  76.  
  77. else if (sender.direction == UISwipeGestureRecognizerDirectionRight)
  78.  
  79. {
  80. index--;
  81.  
  82. }
  83.  
  84. if (index > 0 || index < ([DataArray count] - 1))
  85.  
  86. {
  87. if (index== DataArray.count) {
  88. index=0;
  89.  
  90. }
  91. currentIndex = index;
  92.  
  93. [self showImageAtIndex:currentIndex];
  94.  
  95. }
  96.  
  97. else
  98.  
  99. {
  100. if (index < 0) {
  101.  
  102. index=DataArray.count-1;
  103.  
  104. currentIndex = index;
  105.  
  106. [self showImageAtIndex:currentIndex];
  107.  
  108. }
  109.  
  110. currentIndex = index;
  111.  
  112. [self showImageAtIndex:currentIndex];
  113.  
  114. NSLog(@"Reached the end, swipe in opposite direction");
  115.  
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement