【发布时间】:2012-07-14 17:37:52
【问题描述】:
例如,我有一个设置菜单,它通向其他菜单,并且都具有相同的样式。表格视图单元格自定义是这样完成的:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[self dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
}
BOOL isFirstRowInSection = NO;
if (indexPath.row == 0) isFirstRowInSection = YES;
BOOL isLastRowInSection = NO;
int numberOfRowsInSection = [tableView.dataSource tableView:self numberOfRowsInSection:indexPath.section];
if (indexPath.section == 0 && indexPath.row == numberOfRowsInSection - 1) {
isLastRowInSection = YES;
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.bounds];
imageView.image = cellBackgroundImage(cell.bounds.size, isFirstRowInSection, isLastRowInSection);
cell.backgroundView = imageView;
//cell.textLabel.text = @"This is a cell";
return cell;
}
我希望主设置菜单和所有子菜单都使用这个类,但是虽然我希望它们提供自己的数据,例如每个单元格的文本,但我希望它从这里获取单元格样式方法。
我怎样才能做到这一点?目前的想法是将部分数据源协议复制到我自己的委托中,以便他们可以响应。
【问题讨论】:
标签: iphone objective-c ios uitableview customization