View structure from UITableView
I need to implement a level 1 view from a UITableView. Cells that have children will have a "+" symbol, and if the user clicks on it, the cells below it should slide down and the children of the currently selected row should appear. The sliding of the cells should be visible, and if the user clicks the "-" button of an already expanded row, the child cells should return to the parent.
I tried googling but found no pointers.
How do I get started, should I subclass UITableView? Or should I implement my own subclass of the class and handle everything there?
I somehow feel that subclassing UITableView will be easier because it will handle all row selection for us, but I can't figure out how.
Thanks and Regards, Raj
a source to share
You must subclass and UITableViewCell
@interface OutlineCell : UITableViewCell
Then in the ViewController of your table
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath {
NSString* MyIdentifier = @"MyIdentifier";
OutlineCell* cell = (OutlineCell*) [tableView dequeueReusableCellWithIdentifier: MyIdentifier];
if (cell == nil) {
cell = [[OutlineCell alloc] init];
}
// Populate cell data
}
You can define the interface via IB by creating an empty XIB and dragging the UITableViewCell using your own OutlineCell class as the File Owner. Then add buttons, labels, etc.
EDIT: If you want to get an inner table inside a cell, try the same approach by adding a subview to the UITableViewCell you are defining with a UITableView inside it.
a source to share
Can't you maintain a dictionary as a data source? a dictionary containing an array of dictionaries. And an internal dictionary with two key value pairs:
- isExpanded
- information about children.
By checking that bool isExpanded you will get the number of lines. And you need to configure the camera to add buttons. Will this work for you?
you can distinguish between child cells by lightly clicking on the cell content on the right side.
a source to share