简体   繁体   English

在应用程序中自定义UITableview部分

[英]Customise UITableview section in app

In my app I have 3 categories(sections) and in each category I have 3 items(rows). 在我的应用程序中,我有3个类别(节),在每个类别中我都有3个项目(行)。 I have implemented it by using grouped style UITableview . 我已经通过使用分组样式UITableview实现了它。

But the way it is grouping does not suits my app flow. 但是它的分组方式不适合我的应用程序流程。

How can I customise UITableview sections? 如何自定义UITableview部分?

I actually want 3 blocks kind of sections and also I should be able to select the whole block not the individual sub-categories(ie rows). 我实际上想要3个块类型的部分,而且我应该能够选择整个块而不是单个子类别(即行)。 New controller will present when the user selects the whole block. 当用户选择整个块时,将显示新的控制器。 Is their any method like : -didSelectSectionAtIndexpath ? 他们的方法是否像: -didSelectSectionAtIndexpath So that whole action can be performed on the whole section? 这样就可以对整个部分执行整个操作了吗?

You can create custom header view as follows and in same way you can set footer as well 您可以按以下方式创建自定义页眉视图,并以相同的方式设置页脚

For Header 对于标题

-(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;

} }

For Footer 对于页脚

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

You need to create both views in such a way that it will look same a whole (as per your UI requirement) 您需要以这样的方式创建两个视图,使其看起来整体相同(根据您的UI要求)

There is no didSelectSectionAtIndexpath method but you can do some improvisation. 没有didSelectSectionAtIndexpath方法,但是您可以做一些即兴创作。 you can add a button to the entire header section and then present the new controller on this button click event. 您可以将按钮添加到整个标题部分,然后在此按钮单击事件上显示新控制器。

Also call the same new controller on the didselectrowatindexpath . 还要在didselectrowatindexpath上调用相同的新控制器。

Now set cell.selectionStyle = UITableViewCellSelectionStyleNone; 现在设置cell.selectionStyle = UITableViewCellSelectionStyleNone; in cellForRowAtIndexPath . cellForRowAtIndexPath This will give the user the impression that he is actually selection the entire block. 这将给用户留下印象,他实际上是在选择整个块。

You will also have to create the UI smarlty so that the header and row look like one section. 您还必须创建UI smarlty,以便标题和行看起来像一个部分。

Could you please elaborate a little on the question? 您能详细说明一下这个问题吗? What is it that you want to show once the Sections is touched?? 触摸版块后要显示什么? a viewcontroller with the 3 items related to that section or something else?? 一个与该部分或其他内容相关的3个项目的ViewController?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM