views:

216

answers:

1

Okay, I am about getting completely nuts here... :-( I've been trying for weeks now but to no avail. So if someone was able to help me with the following, that would be great!

So here is what I'm trying to do. My app is basically a rss reader. The topics of the rss entries are displayed in a table view. Tapping on an entry opens a web view which displays the whole story. To this web view I have added a toolbar with up and down arrows so the user would be able to jump to the next/previous story without leaving the web view and having to tap another entry in the table. My problem is that I have no idea how to archieve this. Maybe this is related to the structure of my app. My guess is that I have to somehow increment the selected row on tapping the button.

As I said, maybe the code is a bit complicated, so I've posted the whole project here: http://www.schimanke.com/flo.zip It would be great if someone could have a look and tell me what to do. Thanks in advance!

A: 

What you need is to know which row is currently selected on your model. Since you have a reference to the model from your webview, that's easy:

int row = [mainModel.blogEntries indexOfObject:mainModel.selectedBlogEntry];

So all you need after that is to show the next (or previous) entry. Based on your code, it goes like this:

- (void) showNextPrevEntry:(int)increment usingTheOldController:(BlogEntryController *)controller {

    int row = [mainModel.blogEntries indexOfObject:mainModel.selectedBlogEntry];
    if (row+increment<[mainModel.blogEntries count] && row+increment>=0) {
     mainModel.selectedBlogEntry = [ mainModel.blogEntries objectAtIndex:row+increment];
     controller.mainModel = mainModel;
     [controller viewDidLoad];
    }

}

I don't think it's healthy to call viewDidLoad. Maybe you need another method just for updating the current loaded view and call that from your viewDidLoad. Also I'm not sure why you are using notifications for handling the button presses from the toolbar, but it works. :)

leolobato