Search code examples
iosobjective-ciphonestoryboarduistoryboardsegue

Segue to a new version of the current view controller


In the popular app Instagram when you click on a user it shows their profile. If you click on another users name (in a comment on a photo maybe) then it shows that second person's profile.

I am trying to achieve something similar using Objective-C and the Storyboard. I have what you could consider an account page and within that page are other users. I can get to one account page but I am running into trouble getting that endless stream of account pages that you would see in an app like Instagram, one of the reasons is you can't perform a segue to the same view controller. I tried to get around it by programmatically presenting a new account page when you click on a new user from within an account page but I ran into lots of errors.

What is a way that I can achieve that endless stream of the same view controllers (obviously I am using a navigationController since that would probably have been asked of me).

EDIT Using the solution provided by @tmac_balla (thank you for the help) I can segue to a new tableview but the tableView is blank and I get the following error message.

*** Assertion failure in -[UITableView     _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-  3512.30.14/UITableView.m:7962
2016-01-02 17:06:46.765 Quoter[1631:845864] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x146096000; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x1456c19b0>; layer = <CALayer: 0x1456c0330>; contentOffset: {0, -64}; contentSize: {320, 400}>) failed to obtain a cell from its dataSource (<_UIFilteredDataSource: 0x145727b20>)'

EDIT 2 Using the solution provided by @Daniel T. I am able to push a new view controller onto the navigation stack and the non tableView portion of the controller works fine but when it comes to the cells in the tableView I have (in my short testing) see a scenario where the cells do not appear on the new tableView but rather appear on the previous one. Not sure if that just is my fault with how I am loading the cells or a problem with the solution.


Solution

  • Just make a segue to the same view controller. Here is an example of a button that segues to (another copy of) the view controller it is in.

    enter image description here