2010-07-25 6 views
0

J'ai un UITableView qui contient 3 NSArrays et 3 NSDictionaries pour chaque tableau.Problèmes UITableView multi-section


    - (void)viewDidLoad { 
    [super viewDidLoad]; 
    contentArray = [[NSMutableArray alloc] init]; 

    self.settingsArray = [NSArray arrayWithObjects:@"Settings", nil]; 
    NSDictionary *settingsDict = [NSDictionary dictionaryWithObject:settingsArray forKey:@"Settings"]; 

    self.infoArray = [NSArray arrayWithObjects: @"Version 1.0", @"© Copyrights 2010", @"Developer Site", @"App Page", @"Report a Bug", nil]; 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:infoArray forKey:@"Settings"]; 

    self.contactArray = [NSArray arrayWithObjects: @"Developer Site", @"App Page", @"Report a Bug", nil]; 
    NSDictionary *contactDict = [NSDictionary dictionaryWithObject:contactArray forKey:@"Settings"]; 

    [contentArray addObject:infoDict]; 
    [contentArray addObject:settingsDict]; 
    [contentArray addObject:contactDict]; 
    } 


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


    if ([[infoArray objectAtIndex:indexPath.row] isEqual:@"Version 1.1"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[infoArray objectAtIndex:indexPath.row] isEqual:@"© Copyrights 2010"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[settingsArray objectAtIndex:indexPath.row] isEqual:@"Settings"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"NULL" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"Developer Site"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"App Page"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

    if ([[contactArray objectAtIndex:indexPath.row] isEqual:@"Report a Bug"]) { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES];  
    } 
} 


Le problème est quand je suis en train de sélectionner une ligne, l'application se bloque

Merci

+0

Quel message d'erreur est enregistré? – Kurbz

+0

2010-07-25 21: 58: 19.355 Double recherche [48109: 207] *** Terminaison de l'application en raison d'une exception non interceptée 'NSRangeException', raison: '*** - [NSCFArray objectAtIndex:]: index (4) au-delà des limites (1) » 2010-07-25 21: 58: 19,355 double Recherche [48109: 207] Stack: ( 43292752, 44450604 , 43030283, 43030122 , 748457, 187239 , 49603, 3.416.117, 3375658, 330631 , 42571740, 42567848 , 51927197, 51927394 , 3.056.498, 9476,) terminate appelée après avoir lancé une instance de 'NSException' –

Répondre

0

Cette erreur se produit lorsque vous tentez d'accéder à un index au-delà des limites d'un tableau. Par exemple, vous rencontrerez une exception NSRangeException si votre tableau n'a qu'un seul élément et vous demandez l'objet à l'index 3. La solution immédiate est de vérifier la taille du tableau avant d'interroger son contenu.

NSArray* exampleArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; 
int items = [exampleArray count]; 
if(indexPath.row < items) { 
    // do stuff 
} 
+0

Merci, mais j'ai plusieurs tableaux. Tableau pour chaque section. –

+0

Oui, mais vous essayez d'accéder aux trois dans didSelectRow. – Justin

+0

Je l'ai essayé et je me suis encore écrasé. J'ai fait je peu vérifier et tous les objets peu importe dans quel tableau va au dernier index du troisième tableau –