在我的应用程序中,我有 3 个类别(部分),每个类别中有 3 个项目(行)。
我已经通过使用分组样式 UITableview
来实现它.
但它的分组方式不适合我的应用程序流程。
如何定制UITableview
部分?
我实际上想要 3 个 block 类型的部分,而且我应该能够选择整个 block 而不是单个子类别(即行)。当用户选择整个 block 时,将出现新的 Controller 。他们有什么方法吗:-didSelectSectionAtIndexpath
?所以可以对整个部分执行整个操作?
最佳答案
您可以按如下方式创建自定义页眉 View ,并以同样的方式设置页脚
对于标题
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string =[list objectAtIndex:section];
/* Section header is in 0th index... */
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
return view;
}
对于页脚
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default or specified footer height
您需要以一种整体看起来相同的方式创建两个 View (根据您的 UI 要求)
关于ios - 自定义应用程序中的 UITableview 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21525899/