开发者

Navigating with a UITableView and a detail view

开发者 https://www.devze.com 2023-02-09 06:25 出处:网络
I am sure this is a straight forward application, but not sure what the best way is (and this is all new). I have a Navigation Controller with a UITableViewController (all running in UITabViewControll

I am sure this is a straight forward application, but not sure what the best way is (and this is all new). I have a Navigation Controller with a UITableViewController (all running in UITabViewController).

When a user taps a row the App goes to a detailed view. Now I am trying to link left and right swipe gestures to navigating the to previous and next record. But what is the right way to do this from within the detailed view, what is the easiest to get a link back to my TableViewController?

A related question is then how I could link a 'pull down' to 开发者_运维百科the same action as the 'back' button of the Navigation Controller.

I hope the above makes sense. Thanks a million in advance!


I have something working kind-of in the way I like, but it is very clumsy. When calling the DetailView I pass as parameter the pointer to 'self' and the current 'selectedRow'. Then when a swipe is made I call the function 'moveToNextRecord' on the tabelViewController (with the pointer provided) and have the selectedRow as a parameter. In the tableViewController I then call selectRowAtIndexPath and didSelectRowAtIndexPath.

-(void)moveToNextRecord:(NSIndexPath*) selectedRow{
    //[self.navigationController popViewControllerAnimated:YES];
    //NSIndexPath *selectedRow = [self.tableView indexPathForSelectedRow];
    NSUInteger row = selectedRow.row;
    NSUInteger section = selectedRow.section;
    ++row;
    if(row >= [self.tableView numberOfRowsInSection:selectedRow.section])
    {
        row = 0;
        ++section;
        if(section >= [self.tableView numberOfSections])
        {
            row = 0;
            section = 0;
        }
    }
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
}

This seems to work, but the problem is that the next record is slotted after the previous one. This means that the back-button brings me back to the previous record and not back to the table view. So I guess I should tell the ViewController that I don't want to stack them but basically am going back and then select the next row, while showing the animation directly from one detailView to the next. Does that makes sense?

([self.navigationController popViewControllerAnimated:YES] as first fiction does not seem to work as it does not proper flow.)


From the detail view, once you recognize the gesture, then call:

[self.navigationController popViewControllerAnimated:YES];

this will navigate back.


I am moving towards a PageControl solution, as it is a much improved user experience as the page actually moves at the same time the user swipes. With the above suggestion I would need to over-ride the 'back' button, and manually populate the ViewController-stack in order to allow a left-to-right transition when doing a right swipe (and it only happens when the swipe is completed)

0

精彩评论

暂无评论...
验证码 换一张
取 消