J'ai ajouté l'interfaceOrientation à mon application. Cela fonctionne bien concernant les points de vue. Certaines des cellules de table que j'ai définies par CGRects pour positionner le texte dans la cellule. En mode portrait, la cellule a une longueur de 300 pixels, en mode paysage 420 pixels. J'utilise le code suivant pour changer les CGRects selon l'orientation:cellules "reset" après changement d'orientation
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.interfaceOrientation == UIDeviceOrientationPortrait) {
NSString *currentLanguage = [[NSString alloc] initWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/sprache.txt"]];
static NSString *TableViewTableCellIdentifier = @"TableViewTableCellIdentifier";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:TableViewTableCellIdentifier];
CGRect cellRect = CGRectMake(0, 0, 300, 175);
cell.backgroundColor = [UIColor darkGrayColor];
cell = [[[UITableViewCell alloc] initWithFrame:cellRect reuseIdentifier:TableViewTableCellIdentifier] autorelease];
CGRect keyLabelRect = CGRectMake(0, 5, 5, 20);
UILabel *keyLabel = [[UILabel alloc]initWithFrame:keyLabelRect];
keyLabel.tag = 100; //.........
} else {
NSString *currentLanguage =
[[NSString alloc] initWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/sprache.txt"]];
static NSString *TableViewTableCellIdentifier = @"TableViewTableCellIdentifier";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:TableViewTableCellIdentifier];
CGRect cellRect = CGRectMake(0, 0, 450, 175);
cell.backgroundColor = [UIColor darkGrayColor];
cell = [[[UITableViewCell alloc] initWithFrame:cellRect reuseIdentifier:TableViewTableCellIdentifier] autorelease];
CGRect keyLabelRect = CGRectMake(0, 5, 5, 20);
UILabel *keyLabel = [[UILabel alloc] //.....
}
}
Mon problème est, lorsque la table est visible et l'orientation est modifiée, je dois faire défiler pour voir la nouvelle « mise en page ». Comment puis-je "recharger" la vue après avoir changé l'orientation?
Votre recommandation avec différents view-controllers fonctionne correctement. Merci. Mais comment gérez-vous quand l'utilisateur change d'orientation? Je choisis dans le viewcontroller0 l'orientation: portrait -> viewControllerA, landscape -> viewControllerB. Par exemple, viewControllerA a été sélectionné, puis l'utilisateur a changé son orientation. Il doit quitter le viewControllerA actuel et le viewControllerB correct sera choisi. – Christian
Dans la méthode 'willRotateToOrientation' de chaque contrôleur, vous poussez le contrôleur de vue pour cette orientation sur la pile de navigation sans animation. Lorsque vous retournez, vous faites disparaître la dernière vue. L'utilisateur ne peut pas dire qu'ils sont des vues différentes. – TechZen