ExampleTableViewController.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // ExampleTableViewController.m
  3. // IQKeyboard
  4. //
  5. // Created by Iftekhar on 27/09/14.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. #import "ExampleTableViewController.h"
  9. @interface ExampleTableViewController ()<UITableViewDataSource,UITableViewDelegate,UIPopoverPresentationControllerDelegate>
  10. @end
  11. @implementation ExampleTableViewController
  12. - (void)viewDidLoad
  13. {
  14. [super viewDidLoad];
  15. }
  16. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  17. {
  18. return 10;
  19. }
  20. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  21. {
  22. if (indexPath.row %2)
  23. {
  24. return 40;
  25. }
  26. else
  27. {
  28. return 160;
  29. }
  30. }
  31. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  32. {
  33. NSString *identifier = [NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
  34. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  35. if (cell == nil)
  36. {
  37. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  38. cell.backgroundColor = [UIColor clearColor];
  39. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  40. if (indexPath.row %2)
  41. {
  42. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(5,5,cell.contentView.frame.size.width-10,30)];
  43. textField.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
  44. [textField setPlaceholder:identifier];
  45. [textField setBorderStyle:UITextBorderStyleRoundedRect];
  46. [cell.contentView addSubview:textField];
  47. }
  48. else
  49. {
  50. UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(cell.contentView.bounds, 5, 5)];
  51. textView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  52. textView.text = @"Sample Text";
  53. [cell.contentView addSubview:textView];
  54. }
  55. }
  56. return cell;
  57. }
  58. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  59. {
  60. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  61. {
  62. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  63. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  64. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  65. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  66. segue.destinationViewController.popoverPresentationController.delegate = self;
  67. }
  68. }
  69. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  70. {
  71. return UIModalPresentationNone;
  72. }
  73. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  74. {
  75. [self.view endEditing:YES];
  76. }
  77. @end