2010-10-26 5 views
1

Comment ajouter des données à UITableView? J'ai besoin tableau de données insérées dans ce point de vueComment ajouter des données à UITableView?

UITableView *tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain]; 
[table numberOfRowsInSection:20]; 
table.backgroundColor = [UIColor clearColor]; 

Répondre

5

Vous devez mettre en œuvre le protocole UITableViewDataSource. Jetez un coup d'œil à la section Populating the Table View With Data du Guide de programmation Table View iOS.

Tout simplement parce que copier/coller est tellement amusant, voici les méthodes importantes que vous avez besoin:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [regions count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Number of rows is the number of time zones in the region for the specified section. 
    Region *region = [regions objectAtIndex:section]; 
    return [region.timeZoneWrappers count]; 
} 


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    // The header for the section is the region name -- get this from the region at the section index. 
    Region *region = [regions objectAtIndex:section]; 
    return [region name]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *MyIdentifier = @"MyIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; 
    } 
    Region *region = [regions objectAtIndex:indexPath.section]; 
    TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row]; 
    cell.textLabel.text = timeZoneWrapper.localeName; 
    return cell; 
Questions connexes