ScrollViewController.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // ViewController.m
  3. // KeyboardTextFieldDemo
  4. #import "ScrollViewController.h"
  5. @interface ScrollViewController ()<UIPopoverPresentationControllerDelegate>
  6. @end
  7. @implementation ScrollViewController
  8. #pragma mark - View lifecycle
  9. - (void)viewDidLoad
  10. {
  11. [super viewDidLoad];
  12. [scrollViewDemo setContentSize:CGSizeMake(0,321)];
  13. [scrollViewInsideScrollView setContentSize:CGSizeMake(0,321)];
  14. // [scrollViewOfTableViews setContentSize:CGSizeMake(0,scrollViewOfTableViews.bounds.size.height)];
  15. }
  16. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  17. {
  18. return 5;
  19. }
  20. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  21. {
  22. NSString *identifier = [NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
  23. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  24. if (cell == nil)
  25. {
  26. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  27. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  28. cell.backgroundColor = [UIColor clearColor];
  29. CGRect textFieldRect = CGRectInset(cell.contentView.bounds, 5, 5);
  30. UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];
  31. textField.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth;
  32. [textField setPlaceholder:identifier];
  33. [textField setBorderStyle:UITextBorderStyleRoundedRect];
  34. [cell.contentView addSubview:textField];
  35. }
  36. return cell;
  37. }
  38. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  39. {
  40. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  41. {
  42. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  43. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  44. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  45. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  46. segue.destinationViewController.popoverPresentationController.delegate = self;
  47. }
  48. }
  49. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  50. {
  51. return UIModalPresentationNone;
  52. }
  53. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  54. {
  55. [self.view endEditing:YES];
  56. }
  57. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  58. {
  59. return YES;
  60. }
  61. - (BOOL)shouldAutorotate
  62. {
  63. return YES;
  64. }
  65. @end