NIMCommonTableData.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // NIMCommonTableData.m
  3. // NIM
  4. //
  5. // Created by chris on 15/6/26.
  6. // Copyright © 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMCommonTableData.h"
  9. #define DefaultUIRowHeight 50.f
  10. #define DefaultUIHeaderHeight 44.f
  11. #define DefaultUIFooterHeight 44.f
  12. @implementation NIMCommonTableSection
  13. - (instancetype) initWithDict:(NSDictionary *)dict{
  14. if ([dict[Disable] boolValue]) {
  15. return nil;
  16. }
  17. self = [super init];
  18. if (self) {
  19. _headerTitle = dict[HeaderTitle];
  20. _footerTitle = dict[FooterTitle];
  21. _uiFooterHeight = [dict[FooterHeight] floatValue];
  22. _uiHeaderHeight = [dict[HeaderHeight] floatValue];
  23. _uiHeaderHeight = _uiHeaderHeight ? _uiHeaderHeight : DefaultUIHeaderHeight;
  24. _uiFooterHeight = _uiFooterHeight ? _uiFooterHeight : DefaultUIFooterHeight;
  25. _rows = [NIMCommonTableRow rowsWithData:dict[RowContent]];
  26. }
  27. return self;
  28. }
  29. + (NSArray *)sectionsWithData:(NSArray *)data{
  30. NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:data.count];
  31. for (NSDictionary *dict in data) {
  32. if ([dict isKindOfClass:[NSDictionary class]]) {
  33. NIMCommonTableSection * section = [[NIMCommonTableSection alloc] initWithDict:dict];
  34. if (section) {
  35. [array addObject:section];
  36. }
  37. }
  38. }
  39. return array;
  40. }
  41. @end
  42. @implementation NIMCommonTableRow
  43. - (instancetype) initWithDict:(NSDictionary *)dict{
  44. if ([dict[Disable] boolValue]) {
  45. return nil;
  46. }
  47. self = [super init];
  48. if (self) {
  49. _title = dict[Title];
  50. _detailTitle = dict[DetailTitle];
  51. _cellClassName = dict[CellClass];
  52. _cellActionName = dict[CellAction];
  53. _uiRowHeight = dict[RowHeight] ? [dict[RowHeight] floatValue] : DefaultUIRowHeight;
  54. _extraInfo = dict[ExtraInfo];
  55. _sepLeftEdge = [dict[SepLeftEdge] floatValue];
  56. _showAccessory = [dict[ShowAccessory] boolValue];
  57. _forbidSelect = [dict[ForbidSelect] boolValue];
  58. }
  59. return self;
  60. }
  61. + (NSArray *)rowsWithData:(NSArray *)data{
  62. NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:data.count];
  63. for (NSDictionary *dict in data) {
  64. if ([dict isKindOfClass:[NSDictionary class]]) {
  65. NIMCommonTableRow * row = [[NIMCommonTableRow alloc] initWithDict:dict];
  66. if (row) {
  67. [array addObject:row];
  68. }
  69. }
  70. }
  71. return array;
  72. }
  73. @end