TableViewInContainerViewController.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // TableViewInContainerViewController.m
  3. // IQKeyboard
  4. //
  5. // Created by Jeffrey Sambells on 2014-12-05.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. #import "TableViewInContainerViewController.h"
  9. @interface TableViewInContainerViewController ()<UIPopoverPresentationControllerDelegate>
  10. @end
  11. @implementation TableViewInContainerViewController
  12. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  13. {
  14. return 1;
  15. }
  16. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  17. {
  18. return 30;
  19. }
  20. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  21. {
  22. static NSString *identifier = @"TestCell";
  23. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  24. if (cell == nil)
  25. {
  26. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  27. cell.backgroundColor = [UIColor clearColor];
  28. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10,0,cell.contentView.frame.size.width-20,33)];
  29. textField.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
  30. textField.center = cell.contentView.center;
  31. [textField setBorderStyle:UITextBorderStyleRoundedRect];
  32. textField.tag = 123;
  33. [cell.contentView addSubview:textField];
  34. }
  35. UITextField *textField = (UITextField *)[cell.contentView viewWithTag:123];
  36. textField.placeholder = [NSString stringWithFormat:@"Cell %@",@(indexPath.row)];
  37. return cell;
  38. }
  39. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  40. {
  41. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  42. {
  43. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  44. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  45. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  46. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  47. segue.destinationViewController.popoverPresentationController.delegate = self;
  48. }
  49. }
  50. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  51. {
  52. return UIModalPresentationNone;
  53. }
  54. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  55. {
  56. [self.view endEditing:YES];
  57. }
  58. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  59. {
  60. return YES;
  61. }
  62. - (BOOL)shouldAutorotate
  63. {
  64. return YES;
  65. }
  66. @end