2010-11-12 28 views
0

J'ai commencé à apprendre xcode et Iphone SDK, j'ai fait un UITableviewCell personnalisé pour une vue de table qui charge NSArrays pour différentes valeurs à travers un seul fichier xib (nib).Personnalisation UITableViewCell ouvre différentes sous-vues xib

Ce que je veux savoir, c'est comment faire en sorte que ces cellules ouvrent différents fichiers xib (nib).

Voici mon fichier.

#import "SimpleTableViewController.h" 
#import "NextViewController.h" 
#import "TableCellView.h" 

@implementation SimpleTableViewController 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    titleList = [[NSArray alloc] initWithObjects: 
     @"Title 1",  @"Title 2",  @"Title 3",  @"Title 4" , nil]; 
    imagesList = [[NSArray alloc] initWithObjects: 
     @"Image 1",  @"Image 2",  @"Image 3", 
     @"Image 4",  nil]; 
    imagesHeader = [[NSArray alloc] initWithObjects: 
     @"ImagePro 1", @"ImagePro 2", 
     @"ImagePro 3", @"ImagePro 4", nil]; 
    descpList = [[NSArray alloc] initWithObjects: @"Description 1", 
     @"Description 2", @"Description 3", 
     @"Description 4", nil]; 

    self.title = @"Text"; 
    [super viewDidLoad]; 
} 


#pragma mark Table view methods 

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

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [titleList count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"MyIdentifier";  
    MyIdentifier = @"tblCellView"; 
    TableCellView *cell = (TableCellView *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    if(cell == nil) {  
     [[NSBundle mainBundle] loadNibNamed:@"TableCellView" owner:self options:nil]; 
     cell = tblCell; 
    }  
    [cell setLabelText:[titleList objectAtIndex:indexPath.row]]; 
    [cell setProductImage:[imagesList objectAtIndex:indexPath.row]]; 
    [cell setDescpText:[descpList objectAtIndex:indexPath.row]]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil]; 
    [self.navigationController pushViewController:nextController animated:YES]; 
    [nextController changeProductText:[titleList objectAtIndex:indexPath.row]]; 
    [nextController changeProductContent:[descpList objectAtIndex:indexPath.row]]; 
    [nextController changeHeaderContent:[imagesHeader objectAtIndex:indexPath.row]]; 
} 

@end 
+3

Format votre question d'abord. .. – lukya

+1

En effet, c'est illisible de cette façon ... – CyberK

+0

Oui, idem ..... – Brad

Répondre

1

Créez les fichiers XIB. (CustomCellOne, CustomCellTwo)

Voici un exemple de la façon d'alterner les cellules:

Changer ces lignes:

MyIdentifier = @"tblCellView"; 

[[NSBundle mainBundle] loadNibNamed:@"TableCellView" owner:self options:nil]; 

A ces lignes:

MyIdentifier = indexPath.row % 2 == 0 ? @"CustomCellOne" : @"CustomCellTwo"; 

[[NSBundle mainBundle] loadNibNamed:indexPath.row % 2 == 0 ? @"CustomCellOne" : @"CustomCellTwo" owner:self options:nil]; 
+0

Salut Brandon Merci pour votre aide! bien que ça ne marche pas! Voici l'exemple sur lequel j'essaie de travailler! http://bit.ly/18k2xy si vous pouviez jeter un coup d'oeil ... merci Encore – user505790