开发者

Fetching from the NSFetchedResultsController directly

开发者 https://www.devze.com 2023-03-06 05:20 出处:网络
I have a view controller that is used to populate data from the core data modal into UITableView, in the tableViewDidSelect开发者_如何学PythonRowAtIndexPath delegate method I initialized another view

I have a view controller that is used to populate data from the core data modal into UITableView, in the tableViewDidSelect开发者_如何学PythonRowAtIndexPath delegate method I initialized another view controller and show individual data into the textview. My code for initializing the view controller looks like this,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    myViewController=[[MyViewController alloc] initWithManagedObject:[self.fetchedResultsController objectAtIndexPath:indexPath] parentViewController:self];
    myViewController.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:myViewController animated:YES];
    [transcribedTextViewController release];
    }
}

Now, In the new view controller, I have used to populate the data from the model passed above to fill UITextView. But I do have a next and previous button in it and I would want to access the fetchedResultsController with the managed object that I have it could be done simply by making use of parentViewController. But how do I fetch the next data. I would want to fetch the next data upon next button. Is it possible to increase the NSIndexPath directly from the new view controller and use it to fetch the modal. Please suggest me.


If you send a reference to your fetchedResultsController to myViewController, you can get the next object by creating a new indexPath (increment the row) and use objectAtIndexPath again. You'll have to check that there really is a next object first. This is more complicated if there are sections involved.

If you don't want to pass the fetchedResultsController, you can find a reference to it in one of the Core Data objects (can't remember which).

0

精彩评论

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

关注公众号