开发者

Is there a way to change sectioned tableview to drilldown tableview?

I have a sectioned tableview with a plist wich is an array filled with dictionaries.开发者_如何学JAVA In my app all sections and cells are shown on the first view. But now I need to change it to look like this: sections have to become cells(with names of sections). When you press this cell the cells contained in section have appear.

Is there a way to do it without too much rewriting the code?

Thanks and sorry for the noob question :o)


I understand, that you still want to use one tableview, where cells are hidden for all sections except one. In that case you can do this:

  • Implement -tableView:headerForSection: and place a button on the view that you will return. Write the sections number on the buttons tag. Add an action to the button with parameter (UIButton *)sender: `-(void) headerPressed:(UIButton *)sender
  • You need to implement -tableView:heightforHeaderInSection: as-well.
  • -(void) headerPressed:(UIButton *)sender writes the senders tag to a member integer and reloads the tableview.
  • in -tableview:numberOfRowsInSection: you return 0 if the sections int is not equal to the member integer you saved. If it is equal, return the number of rows in that section.


You will need to create two table view classes. One for the one that holds the section names, and the other that holds the rows of each section. In the first one, retrieve the section names from the plist and populate the rows in the table accordingly. Then in the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method you need to push another view controller onto the navigation stack(something like this-provided in the template code):

// Navigation logic may go here. Create and push another view controller.

     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];

Then for the other table view class you populate it by reading in the info from the plist that corresponds to the tapped section. Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜