2010-12-06 10 views

Répondre

2

Vous devez d'abord prendre l'objet IBOutlet de UITableView dans le fichier d'interface, puis le lier à l'aide du constructeur d'interface. Définissez le délégué et la source de données de UITableView dans la propriété constructeur d'interface.

Et faites le codage suivant dans votre projet.

Dans le fichier .h:

@interface RootViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource> { 

    IBOutlet UITableView *tblView; 
} 

Dans le fichier .m:

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

// Personnalisez le nombre de lignes dans la vue de la table.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return n;// n for number of row. 
} 

// Personnalisez l'aspect des cellules de vue de table.

- (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]; 
    } 

    // Configure the cell. 

    return cell; 
}