我实现了类似的东西,只是滥用节和节页脚。为应该组合在一起的每组重要的行使用部分(这是单元格样式“分组”的重点)
例如,您可以创建一个枚举来跟踪它们:
enum Sections
{
SectionName,
SectionPhone,
SectionAddress,
// etc...
SectionCount
};
然后,像往常一样使用这些部分:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return SectionCount;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == SectionName)
{
return 2; // First name, last name
}
else if (section == SectionPhone)
{
return 1; // Just his phone number
}
else if (section == SectionAddress)
{
return 4; // Country, State, Street, Number
}
// etc...
}
要拥有“动作”,您可以添加与特定部分相关的动作,然后只需添加两个方法
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 52;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// Only the Address has action buttons, for example
if (section != SectionAddress)
{
return nil;
}
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 setTitle:@"Action 1" forState:UIControlStateNormal];
[button2 setTitle:@"Action 2" forState:UIControlStateNormal];
[button3 setTitle:@"Action 3" forState:UIControlStateNormal];
button1.frame = CGRectMake(8, 8, 96, 44);
button2.frame = CGRectMake(button1.frame.origin.x + button1.frame.size.width + 8, 8, 96, 44);
button3.frame = CGRectMake(button2.frame.origin.x + button1.frame.size.width + 8, 8, 96, 44);
[view addSubview:button1];
[view addSubview:button2];
[view addSubview:button3];
return view;
}
返回具有独立按钮的视图。