CollectionViewDemoController.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // CollectionViewDemoController.m
  3. // IQKeyboard
  4. //
  5. // Created by Iftekhar on 29/10/14.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. #import "CollectionViewDemoController.h"
  9. @interface CollectionViewDemoController ()<UICollectionViewDelegate,UIPopoverPresentationControllerDelegate>
  10. @property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
  11. @end
  12. @implementation CollectionViewDemoController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. }
  17. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  18. {
  19. return 20;
  20. }
  21. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  22. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  23. {
  24. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TextFieldCollectionViewCell" forIndexPath:indexPath];
  25. UITextField *textField = (UITextField*)[cell viewWithTag:10];
  26. textField.placeholder = [NSString stringWithFormat:@"%ld, %ld", (long)indexPath.section, (long)indexPath.row];
  27. return cell;
  28. }
  29. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  30. {
  31. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  32. {
  33. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  34. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  35. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  36. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  37. segue.destinationViewController.popoverPresentationController.delegate = self;
  38. }
  39. }
  40. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  41. {
  42. return UIModalPresentationNone;
  43. }
  44. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  45. {
  46. [self.view endEditing:YES];
  47. }
  48. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  49. {
  50. return YES;
  51. }
  52. - (BOOL)shouldAutorotate
  53. {
  54. return YES;
  55. }
  56. @end