2016-01-10 5 views
2

Je pense que c'est un bug.Deux UITableView dans le même contrôleur

IOS 7.0, XCode 5.

J'ai une table View Controller dans mon story-board. J'ai un TableView avec "3" cellules statiques. Puis j'ai ajouté une "Vue" et dedans j'ai ajouté un TableView avec des prototypes dynamiques.

Lorsque j'essaie d'ajouter plus de "3" cellules dans la table dynamique, l'application se bloque.

2016-01-10 08:18:21.358 Know[1381:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]' 
*** First throw call stack: 
(
    0 CoreFoundation      0x017535e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x014d68b6 objc_exception_throw + 44 
    2 CoreFoundation      0x01707a32 -[__NSArrayI objectAtIndex:] + 210 
    3 UIKit        0x00772983 -[UITableViewDataSource tableView:heightForHeaderInSection:] + 50 
    4 UIKit        0x00504fba -[UITableViewController tableView:heightForHeaderInSection:] + 61 
    5 UIKit        0x00333920 -[UITableView _delegateWantsHeaderForSection:] + 349 
    6 UIKit        0x0049a8f7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 133 
    7 UIKit        0x0049eb3d -[UITableViewRowData numberOfRows] + 98 
    8 UIKit        0x003274c2 -[UITableView noteNumberOfRowsChanged] + 120 
    9 UIKit        0x00326e6f -[UITableView reloadData] + 814 
    10 UIKit        0x0032a8d3 -[UITableView _reloadDataIfNeeded] + 65 
    11 UIKit        0x0032f4f4 -[UITableView layoutSubviews] + 36 
    12 UIKit        0x002b3dd7 -[UIView(CALayerDelegate) 

C'est le nombre de sections pour la table statique.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    if (tableView == self.ismTableView) { 
     return 4; 
    } else { 
     // Static sections 
     return 3; 
    } 
} 

Même si je vérifie le nom de table et retour comptage proprement dit, il ne semble pas prendre.

+0

Et vous avez la vue de la table dans chaque méthode? Pourquoi n'utilisez-vous pas les contrôleurs de vue enfants? – Wain

+0

@Wain Oui, vérifiez toutes les méthodes. Comment utiliser le contrôleur de vue enfant? Que devrais-je spécifier pour la classe personnalisée? – ATOzTOA

Répondre

0

Got it!

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    if (tableView == self.ismTableView) { 
     return 1; 
    } else { 
     // Static sections 
     return 3; 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows. 
    if (tableView == self.ismTableView) { 
     return 4; 
    } else { 
     // Static sections 
     return 1; 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 0; 
} 

Sans ajouter indentationLevelForRowAtIndexPath, il jetais une autre exception:

2016-01-10 08:32:07.134 Know[1607:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 
*** First throw call stack: 
(
    0 CoreFoundation      0x017535e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x014d68b6 objc_exception_throw + 44 
    2 CoreFoundation      0x01707a32 -[__NSArrayI objectAtIndex:] + 210 
    3 UIKit        0x00772b9e -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 127 
    4 UIKit        0x0050509a -[UITableViewController tableView:indentationLevelForRowAtIndexPath:] + 61 
    5 UIKit        0x00332035 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1786 
    6 UIKit        0x002aaf5f +[UIView(Animation) performWithoutAnimation:] + 82 
    7 UIKit        0x002aafa8 +[UIView(Animation) _performWithoutAnimation:] + 40 
    8 UIKit        0x00331936 -[UITableView _configureCellForDisplay:forIndexPath:] + 108 
    9 UIKit        0x00337d4d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442 
    10 UIKit        0x00337e03 -[UITableView _createPreparedCellForGlobalRow:] + 69 
    11 UIKit        0x0031c124 -[UITableView _updateVisibleCellsNow:] + 2378 
    12 UIKit        0x0032f5a5 -[UITableView layoutSubviews] + 213 
    13 UIKit        0x002b3dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 
    14 libobjc.A.dylib      0x014e881f -[NSObject 
1

Le second point de vue de la table appelle l'implémentation par défaut des méthodes tableView, cette mise en oeuvre par défaut fonctionnent avec la propriété tableView du contrôleur (première vue de la table) qui a seulement trois cellules. Donc, je suppose que vous devrez remplacer toutes les méthodes qui reçoivent l'indexPath