MenuTableViewController.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // MenuTableViewController.m
  3. // CommonLibrary
  4. //
  5. // Created by AlexiChen on 15/11/12.
  6. // Copyright © 2015年 AlexiChen. All rights reserved.
  7. //
  8. #import "MenuTableViewController.h"
  9. #import "MenuItem.h"
  10. @implementation MenuTableViewController
  11. - (void)addOwnViews
  12. {
  13. _tableView = [[UITableView alloc] init];
  14. _tableView.dataSource = self;
  15. _tableView.delegate = self;
  16. [self.view addSubview:_tableView];
  17. }
  18. - (void)layoutOnIPhone
  19. {
  20. _tableView.frame = self.view.bounds;
  21. }
  22. #define kWTATableCellIdentifier @"WTATableCellIdentifier"
  23. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  24. {
  25. return _data.count;
  26. }
  27. - (void)configCell:(UITableViewCell *)cell with:(id<MenuAbleItem>)meun
  28. {
  29. cell.textLabel.text = [meun title];
  30. }
  31. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  32. {
  33. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kWTATableCellIdentifier];
  34. if (!cell)
  35. {
  36. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kWTATableCellIdentifier];
  37. }
  38. MenuItem *kv = _data[indexPath.row];
  39. [self configCell:cell with:kv];
  40. return cell;
  41. }
  42. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  43. {
  44. MenuItem *kv = _data[indexPath.row];
  45. [kv menuAction];
  46. }
  47. @end