Dans mon application, j'ai un UITableView et j'ai deux UITableViewCell personnalisés différents. UITableView est initialement chargé avec un type de UITableViewCell personnalisé. Lorsque l'une des cellules est sélectionnée dans mon UITableView, je voudrais changer la cellule qui a été sélectionnée avec l'autre type de UITableViewCell personnalisé. Est-ce possible? Laisse-moi entendre ce que tu as.Modification de UITableViewCell lors de la sélection
Merci, NSNolan
#pragma mark - UITableView delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == [self currentCellIndex]) {
[self setCurrentCellIndex:-1];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
OldCell *cell = (OldCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
else {
[self setCurrentCellIndex:indexPath.row];
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
NewCell *cell = (NewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell = [nibs objectAtIndex:0];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"OldCell";
OldCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"OldCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
return cell;
}
Y a-t-il un bloc de code particulier qui vous pose problème? http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//apple_ref/doc/uid/TP40007451 –
Je ne suis pas ce que vous demandez ou le pertinence du lien. – NSNolan
Vous pouvez y parvenir en ayant une variable d'instance qui contient l'indexPath sélectionné en cours. Puis rechargez la tableview. Dans cellForRowAtIndexPath: vous pouvez vérifier si indexPath est égal à selectedIndexPath, puis initialiser la deuxième cellule personnalisée. – Anupdas