KeyValueTableViewController.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // KeyValueTableViewController.m
  3. // CommonLibrary
  4. //
  5. // Created by Alexi on 14-7-22.
  6. // Copyright (c) 2014年 Alexi Chen. All rights reserved.
  7. //
  8. #import "KeyValueTableViewController.h"
  9. #import "KeyValue.h"
  10. @interface KeyValueTableViewController ()
  11. @end
  12. @implementation KeyValueTableViewController
  13. - (void)addOwnViews
  14. {
  15. _tableView = [[UITableView alloc] init];
  16. _tableView.dataSource = self;
  17. _tableView.delegate = self;
  18. [self.view addSubview:_tableView];
  19. }
  20. - (void)layoutOnIPhone
  21. {
  22. _tableView.frame = self.view.bounds;
  23. }
  24. #define kWTATableCellIdentifier @"WTATableCellIdentifier"
  25. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  26. {
  27. return _data.count;
  28. }
  29. - (void)configCell:(UITableViewCell *)cell with:(KeyValue *)kv
  30. {
  31. cell.textLabel.text = kv.key;
  32. cell.detailTextLabel.text = [kv.value description];
  33. }
  34. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  35. {
  36. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kWTATableCellIdentifier];
  37. if (!cell)
  38. {
  39. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kWTATableCellIdentifier];
  40. }
  41. KeyValue *kv = _data[indexPath.row];
  42. [self configCell:cell with:kv];
  43. return cell;
  44. }
  45. @end