YYTextExample.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <time.h>
  10. #import "YYText.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.title = @"✎ YYText Demo ✎";
  19. self.titles = @[].mutableCopy;
  20. self.classNames = @[].mutableCopy;
  21. [self addCell:@"Text Attributes 1" class:@"YYTextAttributeExample"];
  22. [self addCell:@"Text Attributes 2" class:@"YYTextTagExample"];
  23. [self addCell:@"Text Attachments" class:@"YYTextAttachmentExample"];
  24. [self addCell:@"Text Edit" class:@"YYTextEditExample"];
  25. [self addCell:@"Text Parser (Markdown)" class:@"YYTextMarkdownExample"];
  26. [self addCell:@"Text Parser (Emoticon)" class:@"YYTextEmoticonExample"];
  27. [self addCell:@"Text Binding" class:@"YYTextBindingExample"];
  28. [self addCell:@"Copy and Paste" class:@"YYTextCopyPasteExample"];
  29. [self addCell:@"Undo and Redo" class:@"YYTextUndoRedoExample"];
  30. [self addCell:@"Ruby Annotation" class:@"YYTextRubyExample"];
  31. [self addCell:@"Async Display" class:@"YYTextAsyncExample"];
  32. [self.tableView reloadData];
  33. }
  34. - (void)addCell:(NSString *)title class:(NSString *)className {
  35. [self.titles addObject:title];
  36. [self.classNames addObject:className];
  37. }
  38. #pragma mark - Table view data source
  39. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  40. return _titles.count;
  41. }
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YY"];
  44. if (!cell) {
  45. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YY"];
  46. }
  47. cell.textLabel.text = _titles[indexPath.row];
  48. return cell;
  49. }
  50. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  51. NSString *className = self.classNames[indexPath.row];
  52. Class class = NSClassFromString(className);
  53. if (class) {
  54. UIViewController *ctrl = class.new;
  55. ctrl.title = _titles[indexPath.row];
  56. [self.navigationController pushViewController:ctrl animated:YES];
  57. }
  58. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  59. }
  60. @end