2009-12-01 3 views
0

J'essaye de créer et dessiner un UITableView peuplé par un tableau. J'ai créé un UIViewController et définissez le UIViewController en tant que délégué de ma table. Cependant, il semble que ma méthode cellForRowAtIndexPath n'est pas appelée lorsque la tableview est créée, donc ma table n'est jamais remplie. Qu'est-ce que j'oublie ici? (Toutes les étiquettes sont initialisées dans cette fonction, car j'essaie simplement de créer un menu principal en utilisant une table, toutes les entrées seront réparées).La programmation de l'iphone cellForRowAtIndexPath n'est pas appelée même après le jeu de délégués

// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 

prefTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain]; 

[prefTable setDelegate:self]; 

//NSIndexSet *tmpIndRange = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(0,1)]; 

//[prefTable insertSections:tmpIndRange withRowAnimation:UITableViewRowAnimationNone]; 

//[tmpIndRange release]; 

labelArray = [[NSMutableArray alloc] initWithCapacity:10]; 
[labelArray addObject:NSLocalizedString(@"Account ID",@"C_ACC_ID")]; 
[labelArray addObject:NSLocalizedString(@"Site ID",@"Site_ID")]; 
[labelArray addObject:NSLocalizedString(@"Station ID",@"Station_ID")]; 
[labelArray addObject:NSLocalizedString(@"Encryption Key",@"ENC_KEY")]; 
[labelArray addObject:NSLocalizedString(@"Encryption On",@"ENC_ON")]; 

placeholderArray = [[NSMutableArray alloc] initWithCapacity:10]; 
[labelArray addObject:NSLocalizedString(@"Required",@"Required")]; 
[labelArray addObject:NSLocalizedString(@"Required",@"Required")]; 
[labelArray addObject:NSLocalizedString(@"Required",@"Required")]; 
[labelArray addObject:NSLocalizedString(@"Required",@"Required")]; 
[labelArray addObject:NSLocalizedString(@"Required",@"Required")]; 

self.view = prefTable; 
} 

-(BOOL)textFieldShouldReturn:(UITextField *)textField { 

    NSInteger currenttag = textField.tag; 

    NSLog(@"%d",textField.tag); 

    //accountId = textField.text; 
    //stationId = textField.text; 
    //siteId = textField.text; 

    [textField resignFirstResponder]; 

    return YES; 
} 

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Set up the cell... 

    [cell setAccessoryType:UITableViewCellAccessoryNone]; 
    [cell.textLabel setText:[labelArray objectAtIndex:indexPath.row]]; 
    //((TextInputTableCell *)cell).textField.placeholder = [placeholderArray objectAtIndex:indexPath.row]; 

    return cell;  
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 4; 
} 

Aussi, sera-t-il préférable si j'ai assigné les éléments de menu en utilisant une source de données? Il semble que les en-têtes de section ne peuvent être affectés qu'à l'aide d'une source de données. Merci!

Répondre

3

tableView:cellForRowAtIndexPath: fait partie du protocole UITAfficher DataSource - non UITableViewDelegate. Vous devrez faire de votre contrôleur la source de données de UITableView:

prefTable.dataSource = self; 
+0

Oui ... Je pense que c'est tout. – futureelite7

Questions connexes