1

J'ai créé un bouton de contrôle segmenté flèche vers le haut/bas sur le côté droit de la barre de navigation dans ma vue détaillée. Dans une application basée sur une table, comment puis-je utiliser ces flèches haut/bas pour parcourir les cellules de la table parente?Flèches haut/bas dans la barre de navigation de la vue détaillée pour parcourir les objets dans la table parent

L'exemple de code Apple "NavBar" en a un exemple mais les contrôles ne sont pas fonctionnels.

Le programme iBird a aussi cette fonctionnalité et c'est très bien. Téléchargez le programme "iBird 15" gratuitement.

Des pensées?

Merci!

Répondre

1

j'ai fonctionner avec quelques petits problèmes. Voici mon code actuel. Ce n'est pas très élégant mais ça marche. segmentActionPressed est un ensemble NSInteger dans le fichier .h que j'utilise pour spécifier si le contrôle de segment a été utilisé pour passer à la vue suivante.

- (IBAction)segmentAction:(id)sender{ 
NSIndexPath *selectedRow = CurrentIndexPath; //CurrentIndexPath is an NSIndexPath object that holds the current indexpath. 
NSIndexPath *scrollIndexPath; 
self.segmentActionPressed = 1; 
self.tableView.delegate = self; 

if([sender selectedSegmentIndex] == 0) 
{ 
[self.navigationController popViewControllerAnimated:NO]; 
    if(selectedRow.row == 0) //If on the first row when up button is pressed, send us to the last row. 
    { 
     scrollIndexPath = [NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section]; 
     [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section] animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 
     [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section]]; 
    } 
    if(selectedRow.row > 0)  //If on any other row when up button is pressed, go to the next row above. 
    { 
     scrollIndexPath = [NSIndexPath indexPathForRow:selectedRow.row -1 inSection:selectedRow.section]; 
     [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:scrollIndexPath.row inSection:selectedRow.section] animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 
     [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:scrollIndexPath.row inSection:selectedRow.section]]; 
    } 
} 
else if([sender selectedSegmentIndex] == 1) 
{ 
[self.navigationController popViewControllerAnimated:NO]; 
    if(selectedRow.row == tableDataSource.count -1)  //If on the last row when up down is pressed, go to the first row. 
    { 
     scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:selectedRow.section]; 
     [self.tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 
     [self tableView:self.tableView didSelectRowAtIndexPath:scrollIndexPath]; 
    } 
    if(selectedRow.row < tableDataSource.count -1)  //If on any other row when up down is pressed, go to the next row below. 
    { 
     scrollIndexPath = [NSIndexPath indexPathForRow:selectedRow.row +1 inSection:selectedRow.section]; 
     [self.tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 
     [self tableView:self.tableView didSelectRowAtIndexPath:scrollIndexPath]; 
    } 
}} 

Dans ma méthode de -didSelectRowAtIndexPath, j'ai utilisé le code suivant pour passer à la vue suivante sans animation si les flèches haut/bas sont utilisées.

if (segmentActionPressed == 0) 
    { 
    [self.navigationController pushViewController:tvc animated:YES]; 
    } 
else if (segmentActionPressed == 1) 
    { 
    [self.navigationController pushViewController:tvc animated:NO]; 
    } 

Enfin, je mets le code suivant pour définir le segmentActionPressed à « 0 » lorsque la vue parent apparaît. Je désélectionne également la ligne ici afin que vous puissiez voir quelle ligne a été sélectionnée lorsque vous revenez à la vue parente.

- (void)viewWillAppear:(BOOL)animated { 
self.segmentActionPressed = 0; 
[self.tableView deselectRowAtIndexPath:CurrentIndexPath animated:YES];} 

Le principal problème est que les boutons du segment apparaissent jamais pressés et l'action est envoyé immédiatement au toucher au lieu de lorsque le bouton est libéré comme avec l'action « toucher à l'intérieur ».

0

Vous devriez être en mesure de le faire en appelant selectRowAtIndexPath: animé: scrollPosition dans l'action associée au contrôle segmentée

+0

Comment appeler cela en utilisant - (IBAction) segmentAction: (id) expéditeur: lorsque je ne peux pas utiliser indexPath? – Jonah

+0

Je suis toujours à la recherche d'une réponse à ce problème. Avez-vous d'autres suggestions sur la façon d'implémenter selectRowAtIndexPath: animated: scrollPosition? Merci! – Jonah

+0

J'ai trouvé ce fil avec une question similaire. Je n'ai pas encore réussi à le faire fonctionner, mais cela semble être un pas dans la bonne direction. http://stackoverflow.com/questions/1188242/hitting-a-next-button-for-a-uitableviewcell – Jonah

Questions connexes