1

Ich habe in meiner Detailansicht auf der rechten Seite der Navigationsleiste eine segmentierte Steuerschaltfläche nach oben/unten erstellt. Wie kann ich in einer tabellenbasierten Anwendung diese Aufwärts-/Abwärtspfeile verwenden, um sich durch Zellen in der übergeordneten Tabelle zu bewegen?Auf/Ab-Pfeile in der Navigationsleiste der Detailansicht, um durch Objekte in der übergeordneten Tabelle zu blättern

Der Apple "NavBar" -Beispielcode hat ein Beispiel dafür, aber die Steuerelemente sind nicht funktionsfähig.

Das iBird-Programm hat diese Funktionalität auch und es ist sehr nett. Laden Sie das Programm "iBird 15" kostenlos herunter.

Irgendwelche Gedanken?

Danke!

Antwort

1

Ich habe habe es mit einigen kleinen Problemen zu arbeiten. Hier ist mein aktueller Code. Es ist nicht sehr elegant, aber es funktioniert. segmentActionPressed ist ein NSInteger-Set in der .h-Datei, mit dem ich angeben kann, ob das Segmentsteuerelement zum Wechseln in die nächste Ansicht verwendet wurde.

- (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]; 
    } 
}} 

In meiner -didSelectRowAtIndexPath Methode, habe ich den folgenden Code in der nächsten Ansicht ohne Animation zu bewegen, wenn die Auf-/Ab-Pfeiltaste verwendet werden.

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

Schließlich habe ich den folgenden Code stellen Sie den segmentActionPressed auf „0“ gesetzt, wenn der übergeordneten Ansicht angezeigt wird. Ich deaktiviere auch hier die Zeile, damit Sie sehen können, welche Zeile ausgewählt wurde, wenn Sie zur übergeordneten Ansicht zurückkehren.

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

Das Hauptproblem ist, dass die Segment Tasten nie gedrückt erscheinen und die Aktion wird sofort, wenn statt, wenn die Taste losgelassen wird, wie mit der „retuschieren innen“ Aktion berührt gesendet.

0

sollten Sie in der Lage sein, dies selectRowAtIndexPath durch den Aufruf zu tun: animated: scroll in der Aktion mit dem segmentierten Steuerelement zugeordnet

+0

Wie würde ich dies unter Verwendung - (IBAction) SegmentAction: (ID) Absender: , wenn ich IndexPath nicht verwenden kann? – Jonah

+0

Ich suche immer noch nach einer Antwort auf dieses Problem. Haben Sie weitere Vorschläge zur Implementierung von selectRowAtIndexPath: animated: scrollPosition? Danke! – Jonah

+0

Ich habe diesen Thread mit einer ähnlichen Frage gefunden. Ich habe es noch nicht geschafft, aber es scheint ein Schritt in die richtige Richtung zu sein. http://stackoverflow.com/questions/1188242/hitting-a-next-button-for-a-guideviewcell – Jonah