2010-09-01 8 views
0

J'essaie de mettre à jour mon UITableView et l'implémentation suivante ne fonctionne pas. Je me demande si je fais quelque chose de mal?UITableView ne pas insérer de nouvelle ligne

NSDictionary *newContact = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Name", @"Phone", nil] forKeys: [NSArray arrayWithObjects:strName, strPhone, nil]]; 
[arrQuickDialContacts addObject:newContact]; 

NSLog(@"Returned %@ with phone %@\nNew Count: %d", strName, strPhone, [arrQuickDialContacts count]); 

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([arrQuickDialContacts count] - 1) inSection:0]; 
NSArray *indexPaths = [NSArray arrayWithObject:indexPath]; 

[objQuickDialTableView beginUpdates]; 
[objQuickDialTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
[objQuickDialTableView endUpdates]; 

Voici mes méthodes de délégué pour la UITableView:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    // How many rows? 
    return [arrQuickDialContacts count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    // See if we have any cells available for reuse 
    UITableViewCell *objCell = [tableView dequeueReusableCellWithIdentifier:@"QuickDialCell"]; 
    if (objCell == nil) { 

     // No reusable cell exists, so let's create a new one 
     objCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"QuickDialCell"]; 
    } 

    // Give it data 
    NSDictionary *objRow = [arrQuickDialContacts objectAtIndex: [indexPath row]]; 
    objCell.textLabel.text = [objRow valueForKey:@"Name"]; 

    // Return the created cell 
    return objCell; 

} 

Et enfin, mon viewDidLoad le contenu initial remplit du tableau:

- (void)viewDidLoad { 

    // Load the quick dial contacts 
    NSString *strPlist = [[NSBundle mainBundle] pathForResource:@"QuickDialContacts" ofType:@"plist"]; 
    arrQuickDialContacts = [[NSMutableArray alloc] initWithContentsOfFile: strPlist]; 

    [super viewDidLoad]; 
} 

Merci à l'avance!

+0

est cette mise à jour de la table ou la création de table qui ne fonctionne pas –

+0

Qu'est-ce qui se passe lorsque vous l'exécutez? –

Répondre

0

doivent appeler [tableView reloadData];

Acutally il y a une question similaire avec plus de détails

Unable to update UITableView

+0

J'ai inséré une nouvelle ligne et mis à jour la table sans appeler tableView reloadData. [self.tableView insertRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationAutomatic]; Cela devrait télécharger la table automatiquement. – coolcool1994

Questions connexes