iOS中UITableView中的下拉列表 [英] Drop-Down List in UITableView in iOS

查看:109
本文介绍了iOS中UITableView中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS中创建此类型的tableview?

在这里,如果我们点击第一行'Account',那么它会自动滚动显示在Image中的更多行。
如果我们再点击账户,那么该视图将被隐藏。

Here, If we tap on 1st row 'Account', then automatically it scrolled with some more rows which is showing in Image. And if again we tap on Account, then that view will be hidden.

推荐答案

你可以很容易将单元格设置为像标题一样LOOK,并设置 tableView:didSelectRowAtIndexPath 以手动展开或折叠它所在的部分。如果我存储了布尔数组对应于每个部分的消耗值。然后,您可以在每个自定义标题行上使用 tableView:didSelectRowAtIndexPath 切换此值,然后重新加载该特定部分。

You could easily set up a cell to LOOK like a header, and setup the tableView: didSelectRowAtIndexPath to expand or collapse the section it is within manually. If I'd store an array of booleans corresponding the the "expended" value of each of your sections. You could then have the tableView:didSelectRowAtIndexPath on each of your custom header rows toggle this value and then reload that specific section.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        ///it's the first row of any section so it would be your custom section header

        ///put in your code to toggle your boolean value here
        mybooleans[indexPath.section] = !mybooleans[indexPath.section];

        ///reload this section
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
    }
}

然后设置你的号码 numberOfRowsInSection 检查 mybooleans 值,如果该部分未展开,则返回1,或者该部分中的项目数为1+ ,如果它被扩展。

You'd then setup your number numberOfRowsInSection to check the mybooleans value and return either 1 if the section isn't expanded, or 1+ the number of items in the section, if it is expanded.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (mybooleans[section]) {
        ///we want the number of people plus the header cell
        return [self numberOfPeopleInGroup:section] + 1;
    } else {
        ///we just want the header cell
        return 1;
    }
}

您还需要更新 cellForRowAtIndexPath 返回任何部分第一行的自定义标题单元格

You would also have to update your cellForRowAtIndexPath to return a custom header cell for the first row in any section.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 是提供自己的自定义标题的更好方法,因为这正是它的目的是做。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section is the better way to provide your "own custom header", as that's exactly what it's designed to do.

有关详细信息,请参阅此答案 PKCollapsingTableViewSections

For more details, Refer this Answer or this PKCollapsingTableViewSections.

此外,您可以使用 setIndentationLevel 获取此类表格视图。有关此示例,请参阅此 DemoCode 。我认为这是Drop-Down tableviews的最佳解决方案。

Also, You can get this type of tableviews using setIndentationLevel. Please refer this DemoCode for this example. I think this the best solution for Drop-Down tableviews.

如果你想制作一个简单的标题和单元格下拉,那么请参考 STCollapseTableView

If you want to make a simple header and cell drop down, then please refer STCollapseTableView.

希望,这就是你要找的东西。任何关注都会回复给我。 :)

Hope, this is what you're looking for. Any concern get back to me. :)

这篇关于iOS中UITableView中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆