Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-09-2010, 02:24 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 6
sarahhbabyyyy is on a distinguished road
Default Return back to main view after hitting "Save"

Hey Everyone,

So, I currently have a main view where a user selects the first cell, which leads him to view 2 (that i called by using pushViewController) and from there, the user selects another cell which leads him to view 3.

In view 3, I created a "Save" button on the navigation bar.

My question is: how do i return back to the main view after the user hits Save? Where the order of my views go like this:

Main view -> View 2 -> View 3 -> Main view

I tried using:

[[self navigationController] pushViewController:[MainViewController alloc] animated:YES];

but this just pushes the main view onto view 3, making it look like a subview with a back button.

Please, can someone tell me how to solve this?

Thanks,
Sarah
sarahhbabyyyy is offline   Reply With Quote
Old 06-09-2010, 02:54 PM   #2 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Hi Sarah and welcome to the forum!

If by "main view" you mean root view controller, you can use:

Code:
[self.navigationController popToRootViewControllerAnimated: YES];
"pushing" view controllers adds them to the stack and "popping" view controllers makes you jump back to view controllers further down the stack.

Hope this helps.

Cheers,
Bob



EDIT: On a side note...

Code:
[[self navigationController] pushViewController:[MainViewController alloc] animated:YES];
This is not how you should be pushing view controllers. The best practice is to create an instance of the view controller you want to push, then push it, and then release it. Like this:

Code:
MyViewController *myVC = [[MyViewController alloc] initWithNibName: @"MyFirstView" bundle: nil];
[[self navigationController] pushViewController: myVC animated:YES];
[myVC release];
After you push the view controller onto the stack, the navigation controller will retain it for you and you can release it to avoid memory leaks.
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]

Last edited by Robert Paulson; 06-09-2010 at 03:00 PM.
Robert Paulson is offline   Reply With Quote
Old 06-09-2010, 04:07 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 6
sarahhbabyyyy is on a distinguished road
Default

Thank you SO much! It worked

Sarah
sarahhbabyyyy is offline   Reply With Quote
Reply

Bookmarks

Tags
navigation controller, pushviewcontroller, save

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 334
12 members and 322 guests
Absentia, Domele, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, PixelInteractive, raihan.zbr, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:11 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0