rowsare not consecutive and start at zero in each section:
0:
0
1
2
...
1:
0
1
2
...
...
- NSMutableArray NSMutableArrays . :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return cellSections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
CellSection *cellSection = [cellSections objectAtIndex:section];
return cellSection.cellElements.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = [NSString stringWithFormat:@"Cell-%i-%i", indexPath.section, indexPath.row];
CellSection *cellSection = [cellSections objectAtIndex:indexPath.section];
CellElement *cellElement = [cellSection.cellElements objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
[cell.contentView addSubview:cellElement.contentView];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CellSection *cellSection = [cellSections objectAtIndex:indexPath.section];
CellElement *cellElement = [cellSection.cellElements objectAtIndex:indexPath.row];
}
EDIT:
:
@interface CellSection : NSObject {
}
@property (nonatomic, retain) NSMutableArray *cellElements;
@property (nonatomic, retain) NSString *headerString;
@property (nonatomic, retain) UIView *headerView;
@end
@interface CellElement : NSObject {
}
@property (nonatomic, retain) UIView *contentView;
@property BOOL isSelectable;
@property BOOL hasAccessoryIndicator;
@property SEL action;
@end