Mahesh Babu
Mahesh Babu

Reputation: 3433

how to get back to one view to another view in view based application

I did a simple view based application.

what i did is creating view additional to existing view.

means there is one view named main in .xib file additional to that i am creating another view

IBOutlet UIView *view_additional;

In the main view by button click i call the view_additional view.

For the view_additional view i place navigation bar with one bar button named back.

In the back button click event i need to get back to main view.

for that in the button click action i write the fallowing code.

[view_additional removeFromSuperview];

But it is not open main view,shows a white screen.

what the wrong.

how can i get back from additional view to main view.

Thank u in advance.

Upvotes: 1

Views: 571

Answers (4)

Archana Chaurasia
Archana Chaurasia

Reputation: 1396

@ MaheshBabu: This is the common code u can use to go on next view or go on back, Just change button name which u want to press and the view name on which u want to go. For example on back button press u want to go on library view then write this code -

-(IBAction)backButtonPressed:(id) sender { libraryView *libraryview=[[libraryView alloc] initWithNibName:nil bundle:nil]; libraryview.modalTransitionStyle=UIModalTransitionStyleCoverVertical; [self presentModalViewController:libraryview animated:YES]; [libraryview release]; }

Let me know whether ur problem is solved or not.

Upvotes: 0

Omar
Omar

Reputation: 1574

MahesBabu, that is exactly What I suggested that you do. Only I offered the background info on why you should do it that way.

Upvotes: 0

Mahesh Babu
Mahesh Babu

Reputation: 3433

I resolve my problem as

instead of [self.view = view_additional];

i use

[self addSubview: view_additional];

To get back to original view in the button click

i use

[view_additional removeFromSuperview];

Upvotes: 1

Omar
Omar

Reputation: 1574

for the code you used to display view_additional, instead of using    self.view = view_additional

try using, on button click

[self addSubview: view_additional];

And once that's done, your code should work just fine the way you want.

When dealing with views, if you change a view, then remove it, as you did in your code, then all that will be left is the main app window. There will be no views on that window. From the look of it, you want to load up a new view, and then remove it once you're done with it. You can do this by adding the new view as a subview instead of totally changing the parent view. Another thing you can do is set an IBOutlet for the original view as well, this way you'll have an outlet for both views, and then instead of removing your additional_view from the superview, you can just switch it back. So the code for the Back Button would just be

self.view = original_view;

on back button click. I hope this isn't too confusing for you. Let me know if you have any questions.

Both methods would work for what you want to do.

Upvotes: 1

Related Questions