YYTextExample.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // YYTextExample.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/7/18.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "YYTextExample.h"
  9. #import "YYKit.h"
  10. #import <time.h>
  11. @interface YYTextExample()
  12. @property (nonatomic, strong) NSMutableArray *titles;
  13. @property (nonatomic, strong) NSMutableArray *classNames;
  14. @end
  15. @implementation YYTextExample
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.titles = @[].mutableCopy;
  19. self.classNames = @[].mutableCopy;
  20. [self addCell:@"Text Attributes 1" class:@"YYTextAttributeExample"];
  21. [self addCell:@"Text Attributes 2" class:@"YYTextTagExample"];
  22. [self addCell:@"Text Attachments" class:@"YYTextAttachmentExample"];
  23. [self addCell:@"Text Edit" class:@"YYTextEditExample"];
  24. [self addCell:@"Text Parser (Markdown)" class:@"YYTextMarkdownExample"];
  25. [self addCell:@"Text Parser (Emoticon)" class:@"YYTextEmoticonExample"];
  26. [self addCell:@"Text Binding" class:@"YYTextBindingExample"];
  27. [self addCell:@"Copy and Paste" class:@"YYTextCopyPasteExample"];
  28. [self addCell:@"Undo and Redo" class:@"YYTextUndoRedoExample"];
  29. [self addCell:@"Ruby Annotation" class:@"YYTextRubyExample"];
  30. [self addCell:@"Async Display" class:@"YYTextAsyncExample"];
  31. [self.tableView reloadData];
  32. }
  33. - (void)addCell:(NSString *)title class:(NSString *)className {
  34. [self.titles addObject:title];
  35. [self.classNames addObject:className];
  36. }
  37. #pragma mark - Table view data source
  38. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  39. return _titles.count;
  40. }
  41. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  42. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YY"];
  43. if (!cell) {
  44. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YY"];
  45. }
  46. cell.textLabel.text = _titles[indexPath.row];
  47. return cell;
  48. }
  49. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  50. NSString *className = self.classNames[indexPath.row];
  51. Class class = NSClassFromString(className);
  52. if (class) {
  53. UIViewController *ctrl = class.new;
  54. ctrl.title = _titles[indexPath.row];
  55. [self.navigationController pushViewController:ctrl animated:YES];
  56. }
  57. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  58. }
  59. @end