iPhone表格视图与展开和折叠 [英] iPhone Table View with Expand and Collapsed

查看:142
本文介绍了iPhone表格视图与展开和折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何展开或折叠表视图标题,如果我点击标题,其他标题将崩溃。请把代码或有用的链接发给我....

how to expand or collapsed the table view header and if i click on header other header are collapse. please send me the code or useful links to me....

推荐答案

看看这个示例代码:表格查看动画和手势 [ ^ ]。
Have a look at this sample code: Table View Animations and Gestures[^].


我遇到了类似的功能,构建它粗略的算法将是:



1.实现uitableviewdelgate和uitableviewdatasource协议



2.创建全局变量expandedSectionIndex = -1;

= -1表示全部折叠。

> = 0表示expandedSectionIndex。



I came across similar feature, to build it a rough algorithm will be:

1. implement the uitableviewdelgate and uitableviewdatasource protocols

2. create a global variable expandedSectionIndex = -1;
= -1 represents all collapsed.
>= 0 represents expandedSectionIndex.

//the following protocol definitions will take care of which section is to be expanded.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(expandedSectionIndex == section) return [self.dataArray[section] count];
else return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView [
if(self.dataArray)return [self.dataArray count]; 
}



2.在 - tableView中定义自定义标题视图:viewForHeaderInSection:

- 具有相当于标题视图框架的框架的按钮

- 设置按钮标签属性,其值为节号。

- 将所有按钮与选择器关联 - (void)expand:(id)sender;


2. define custom header views in – tableView:viewForHeaderInSection:
- buttons having frame equivalent to header view frame
- set button tag property with value of section number.
- associate all buttons with selector - (void)expand:(id) sender;

// this event will select the expanded section
- (void)expand:(id) sender {
expandedSectionIndex = [sender tag];
[self.tableView reload];
}





[edit]已添加代码块[/ edit]


这篇关于iPhone表格视图与展开和折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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