谁能告诉我如何实现 expandable/collapse tableview
Can any one tell how to implement expandable/collapse tableview
这是我的屏幕和我附上的代码 below.can 任何人都可以提供如何实现屏幕的想法提前感谢..在我的 header 部分我只需要显示 tableview 单元格.. .....................................
[1]: http://i.stack.imgur.com/EVlQs.png
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [arr count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellidentifier =@"cell";
MyOrderCell *cell = (MyOrderCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
/********** If the section supposed to be closed *******************/
if(cell==nil)
{
cell = [[MyOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
if (selectedindex==indexPath.row) {
// do expanded stuff here
cell.lblcope.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"pendents"];
cell.lblcopieces.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"copiece"];
cell.lblconum.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"conum"];
cell.lblcodate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"codate"];
cell.lblcoenddate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"coenddate"];
cell.lbltotl.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"cototal"];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}else
{
// do closed stuff here
cell.lblpendnts.text=[arr objectAtIndex:indexPath.row];
cell.lblpieces.text=[arrpieces objectAtIndex:indexPath.row];
cell.lblnum.text=[arrnum objectAtIndex:indexPath.row];
cell.lbldate.text=[arrdate objectAtIndex:indexPath.row];
cell.lblenddate.text=[arrenddate objectAtIndex:indexPath.row];
cell.lbltotl.text=[arrttl objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedindex==indexPath.row) {
selectedindex=-1;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
if (selectedindex !=-1) {
NSIndexPath *prevpath=[NSIndexPath indexPathForRow:selectedindex inSection:0];
selectedindex=indexPath.row;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevpath] withRowAnimation:UITableViewRowAnimationFade];
}
selectedindex=indexPath.row;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedindex==indexPath.row) {
return 100;
}else
{
return 50;
}
}
您可以使用 SubTable,UITableView 的第三方子类。除了以下与您相同的问题外,请检查它们:
How to create an Accordion with UItableview under a UItableview?
Accordion table cell - for expand and collapse ios
您可以使用https://github.com/iSofTom/STCollapseTableView
我在一个项目中使用过这个。编写的代码非常干净,因此您也可以轻松自定义它以满足您的特定需求。
确实是 Burak,或者学习教程...
一个例子:https://blog.pivotal.io/labs/labs/expandable-uitableviewcells
这是我的屏幕和我附上的代码 below.can 任何人都可以提供如何实现屏幕的想法提前感谢..在我的 header 部分我只需要显示 tableview 单元格.. .....................................
[1]: http://i.stack.imgur.com/EVlQs.png
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [arr count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellidentifier =@"cell";
MyOrderCell *cell = (MyOrderCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
/********** If the section supposed to be closed *******************/
if(cell==nil)
{
cell = [[MyOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
if (selectedindex==indexPath.row) {
// do expanded stuff here
cell.lblcope.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"pendents"];
cell.lblcopieces.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"copiece"];
cell.lblconum.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"conum"];
cell.lblcodate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"codate"];
cell.lblcoenddate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"coenddate"];
cell.lbltotl.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"cototal"];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}else
{
// do closed stuff here
cell.lblpendnts.text=[arr objectAtIndex:indexPath.row];
cell.lblpieces.text=[arrpieces objectAtIndex:indexPath.row];
cell.lblnum.text=[arrnum objectAtIndex:indexPath.row];
cell.lbldate.text=[arrdate objectAtIndex:indexPath.row];
cell.lblenddate.text=[arrenddate objectAtIndex:indexPath.row];
cell.lbltotl.text=[arrttl objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedindex==indexPath.row) {
selectedindex=-1;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
if (selectedindex !=-1) {
NSIndexPath *prevpath=[NSIndexPath indexPathForRow:selectedindex inSection:0];
selectedindex=indexPath.row;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevpath] withRowAnimation:UITableViewRowAnimationFade];
}
selectedindex=indexPath.row;
[tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedindex==indexPath.row) {
return 100;
}else
{
return 50;
}
}
您可以使用 SubTable,UITableView 的第三方子类。除了以下与您相同的问题外,请检查它们:
How to create an Accordion with UItableview under a UItableview?
Accordion table cell - for expand and collapse ios
您可以使用https://github.com/iSofTom/STCollapseTableView
我在一个项目中使用过这个。编写的代码非常干净,因此您也可以轻松自定义它以满足您的特定需求。
确实是 Burak,或者学习教程... 一个例子:https://blog.pivotal.io/labs/labs/expandable-uitableviewcells