2015-08-26 8 views
8

hallo jeder ich benötige eine ausdehnbare Tabellenansicht für meine Daten, ist es möglich, so in tableView.In meiner Daten jede mit anderen Childs, unten ist meinewie man erweiterbare Tabellenansicht wie Baumstruktur in ios

Daten
-A1 
    -A1.1 
     -A1.1.1 
      A1.1.1.1 
+B1 
+C1 
+D1 

---------------------- 
+A1 
-B1 
    +B1.1 
+C1 
+D1 
----------------------- 
+A1 
+B1 
+C1 
-D1 
    +D1.1 
    -D1.2 
     +D1.2.1 
     +D1.2.2 
    +D1.3 

Helfen Sie mir Vielen dank im Voraus

Antwort

2

try this: -

NSMutableIndexSet *expandedSections; 
    @property (strong, nonatomic) NSIndexPath *expandedIndexPath; 



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) { 
     return 100; 
    } 
    else 
    { 
    return 30; 
    } 

} 


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) { 
     [tableView beginUpdates]; 
     self.expandedIndexPath = nil; 
     [tableView endUpdates]; 
    } 
    else{ 
     self.expandedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]; 

     [tableView beginUpdates]; 

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame)  { 
     self.expandedIndexPath = indexPath; 
    } else { 
     self.expandedIndexPath = nil; 
    } 

    [tableView endUpdates]; 
    } 

} 
1

gibt es UITreeView Beispiel bei Github UITreeView

+0

Vielen Dank @Varun, UITreeView ist die perfekte Wahl – swiftBoy