TextSelectionViewController.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // ViewController.m
  3. // KeyboardTextFieldDemo
  4. #import "TextSelectionViewController.h"
  5. @interface TextSelectionViewController ()<UIPopoverPresentationControllerDelegate>
  6. @property (nonatomic, strong) NSArray *data;
  7. @end
  8. @implementation TextSelectionViewController
  9. @synthesize data = _data;
  10. @synthesize tableView = _tableView;
  11. - (void)viewDidLoad
  12. {
  13. [super viewDidLoad];
  14. self.tableView.delegate = self;
  15. self.tableView.dataSource = self;
  16. _data = @[@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",
  17. @"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",
  18. @"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text."];
  19. }
  20. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  21. {
  22. return _tableView.rowHeight;
  23. }
  24. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  25. {
  26. return _data.count;
  27. }
  28. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  29. {
  30. NSString *identifier = [NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
  31. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  32. if (cell == nil)
  33. {
  34. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  35. cell.backgroundColor = [UIColor clearColor];
  36. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  37. UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5,7,135,30)];
  38. textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  39. textView.backgroundColor = [UIColor clearColor];
  40. textView.text = _data[indexPath.row];
  41. textView.dataDetectorTypes = UIDataDetectorTypeAll;
  42. textView.scrollEnabled = NO;
  43. textView.editable = NO;
  44. [cell.contentView addSubview:textView];
  45. }
  46. return cell;
  47. }
  48. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  49. {
  50. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  51. {
  52. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  53. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  54. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  55. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  56. segue.destinationViewController.popoverPresentationController.delegate = self;
  57. }
  58. }
  59. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  60. {
  61. return UIModalPresentationNone;
  62. }
  63. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  64. {
  65. [self.view endEditing:YES];
  66. }
  67. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  68. {
  69. return YES;
  70. }
  71. - (BOOL)shouldAutorotate
  72. {
  73. return YES;
  74. }
  75. @end