-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICMenuTableSection.m
110 lines (92 loc) · 3.57 KB
/
ICMenuTableSection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// ICMenuTableSection.m
// ModalGroupContacts
//
// Created by marco on 13-3-12.
// Copyright (c) 2013年 marco. All rights reserved.
//
#import "ICMenuTableSection.h"
@implementation ICMenuTableSection
#pragma mark - private
- (NSArray*) getContentRowIndexPaths{
NSMutableArray* updateRows = [NSMutableArray array];
for (NSUInteger i = 1; i < self.contentNumberOfRow + 1; i++){
[updateRows addObject:[NSIndexPath indexPathForRow:i inSection:self.sectionIndex]];
}
return updateRows;
}
- (UITableViewCell *) contentCellForRow:(NSUInteger)row{
NSString* contentCellIdentifier = [NSString stringWithFormat:@"%d%@", self.sectionIndex, @"content"];
UITableViewCell *cell = [self generatCellByCellIdentify:contentCellIdentifier cellClz:contentCellClz];
[self processCell:cell cellData:[self.contentDatas objectAtIndex:row] sectionType:MenuSectionRowTypeContent];
return cell;
}
- (UITableViewCell *) titleCellForSection{
NSString* titleCellIdentifier = [NSString stringWithFormat:@"%d%@", self.sectionIndex, @"title"];
UITableViewCell* cell = [self generatCellByCellIdentify:titleCellIdentifier cellClz:titleCellClz];
[self processCell:cell cellData:self.titleData sectionType:MenuSectionRowTypeTitle];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
- (UITableViewCell*) generatCellByCellIdentify:(NSString*)identify cellClz:(Class)clz{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identify];
if (cell == nil && clz != nil)
cell = [[[clz alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify] autorelease];
return cell;
}
- (void) processCell:(UITableViewCell*)cell cellData:(NSObject*)data sectionType:(MenuSectionRowType)type{
if ([cell respondsToSelector:@selector(setObject:)])
[cell performSelector:@selector(setObject:) withObject:data];
if ([cell respondsToSelector:@selector(setSectionTypeForRow:)])
[cell performSelector:@selector(setSectionTypeForRow:) withObject:(id)type];
}
-(void) updateAccessoryViewOnCell{}
#pragma mark - public
-(void)dealloc{
[_contentDatas release];
[_titleData release];
[super dealloc];
}
- (id) initWithTableView:(UITableView*)tbView
sectionIdx:(NSUInteger)index contentCellClz:(Class)cclz titleCellClz:(Class)tclz{
if ((self = [super init])){
_sectionIndex = index;
contentCellClz = cclz;
titleCellClz = tclz;
self.tableView = tbView;
self.open = NO;
}
return self;
}
- (void) openSection{
if (_open == NO){
_open = YES;
[self updateAccessoryViewOnCell];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[self getContentRowIndexPaths] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
}
}
- (void) closeSection{
if (_open == YES){
_open = NO;
[self updateAccessoryViewOnCell];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[self getContentRowIndexPaths] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
}
}
- (void) reverseSection{
_open ? [self closeSection] : [self openSection];
}
- (UITableViewCell *) cellForRow:(NSUInteger)row{
UITableViewCell* cell = row == 0 ? [self titleCellForSection] : [self contentCellForRow:row - 1];
return cell;
}
- (NSUInteger) contentNumberOfRow{
return _contentDatas!=nil ? _contentDatas.count : 0;
}
- (NSUInteger) numberOfRow {
return (self.open) ? self.contentNumberOfRow + 1 : 1;
}
@end