Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 21, 2012, 10:44 AM   #1
gwelmarten
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Resetting a Modal View every time it's opened

Hi

I've got a View Controller that I open as a Modal View when a button is pressed. This contains some interactive elements, which consist of interface builder objects that move around the screen from their original positions.

I need everything to start from scratch every time the modal view controller i opened. Almost as if closing the view controller close the view completely. Is there a way of doing this?

I know I could simply put into viewWillDisappear the code for sending all the elements back to their original places and removing all the relevant subviews from the view, but I want to find an easier solution. Does anybody have any ideas?

Sam
gwelmarten is offline   0 Reply With Quote
Old Sep 21, 2012, 11:17 AM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
How/where are you instantiating and presenting your modal view?
__________________
dejo is offline   0 Reply With Quote
Old Sep 21, 2012, 11:19 AM   #3
gwelmarten
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Quote:
Originally Posted by dejo View Post
How/where are you instantiating and presenting your modal view?
For the purpose here, lets say I've got VC1 which called VC2 in a modal view from an UIButton.

I can dismiss the modal view inside VC2 when it's showing.

So I could reset VC2 either from VC1 (which I don't think is possible), or either when VC2 appears or when it disappears.

Sam
gwelmarten is offline   0 Reply With Quote
Old Sep 21, 2012, 11:25 AM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gwelmarten View Post
For the purpose here, lets say I've got VC1 which called VC2 in a modal view from an UIButton.
Show us the code. Because if you do something like this inside your IBAction, your modal view should present as "new" every time:
Code:
- (IBAction)buttonPressed:(id)sender {
    VC2 *vc2 = [[VC2 alloc] init];
    [self presentViewController:vc2 animated:YES completion:nil];
}
__________________
dejo is offline   0 Reply With Quote
Old Sep 21, 2012, 11:36 AM   #5
gwelmarten
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Quote:
Originally Posted by dejo View Post
Show us the code. Because if you do something like this inside your IBAction, your modal view should present as "new" every time:
Code:
- (IBAction)buttonPressed:(id)sender {
    VC2 *vc2 = [[VC2 alloc] init];
    [self presentViewController:vc2 animated:YES completion:nil];
}
Ah, ok. I was going this, which is different. I see the relevant doc's now as well. I never thought to look at that way of doing things - I just assumed my way was the only way of opening the modal view and I should find a way of resetting. The code I was using was:

Code:
-(IBAction)openOneHundredMVC {
    OneHundredMViewController *sampleView = [[OneHundredMViewController alloc] init];
    [sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:sampleView animated:YES];
}
Out of interest for future use, is there a way of resetting to the original state without leaving the view?

Thanks again so far,

Sam
gwelmarten is offline   0 Reply With Quote
Old Sep 21, 2012, 11:47 AM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gwelmarten View Post
Code:
-(IBAction)openOneHundredMVC {
    OneHundredMViewController *sampleView = [[OneHundredMViewController alloc] init];
    [sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:sampleView animated:YES];
}
presentModalViewController:animated: is older but should still present the modal view in a "new" state, if you just instantiated the viewController, which you have. Is that not what you were seeing?

Quote:
Originally Posted by gwelmarten View Post
Out of interest for future use, is there a way of resetting to the original state without leaving the view?
Yes, there's a way. But it's not simple and you have to do the work. I believe you would have to keep track of the initial state of all your desired objects and set them back when needed.
__________________
dejo is offline   0 Reply With Quote
Old Sep 21, 2012, 11:54 AM   #7
gwelmarten
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Quote:
Originally Posted by dejo View Post
presentModalViewController:animated: is older but should still present the modal view in a "new" state, if you just instantiated the viewController, which you have. Is that not what you were seeing?



Yes, there's a way. But it's not simple and you have to do the work. I believe you would have to keep track of the initial state of all your desired objects and set them back when needed.
Hi dejo
I've tried the code you sent me for show modal view and both yours and mine seem to do the same.
Basically, some of the view is being reset, but not all of it. All the objects get returned to their original locations, however some boolean values are not being reset, along with other variables.

Sam
gwelmarten is offline   0 Reply With Quote
Old Sep 21, 2012, 12:13 PM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gwelmarten View Post
Basically, some of the view is being reset, but not all of it. All the objects get returned to their original locations, however some boolean values are not being reset, along with other variables.
Again, show your code. Can you guess which code I want to see? We can't help debug based only on rather vague descriptions and we can't see your screen.
__________________
dejo is offline   0 Reply With Quote
Old Sep 21, 2012, 12:23 PM   #9
gwelmarten
Thread Starter
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Quote:
Originally Posted by dejo View Post
Again, show your code. Can you guess which code I want to see? We can't help debug based only on rather vague descriptions and we can't see your screen.
I don't see what code it is you want to see. I declare a boolean at the top of my implemtation file, then set it to NO. I then change it after a method has being run to YES. Except that when the user re-opens the modal view, it's already set to YES.

Are you saying you want to see the declaration of the variable? Or the method by which it changes?
gwelmarten is offline   0 Reply With Quote
Old Sep 21, 2012, 12:35 PM   #10
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gwelmarten View Post
Are you saying you want to see the declaration of the variable? Or the method by which it changes?
All of that... and more. Any code that is run during the initialization and presentation, including any init/initWith... methods, viewDidLoad, viewWillAppear, viewDidAppear (and any supporting methods that they might call). Does it make sense why I want to see all those?
__________________
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
ios, modal, reset, view controller, viewdidload

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Modal view controller presenter problem moonman239 iPhone/iPad Programming 4 Mar 6, 2014 04:47 PM
Resolved: How do I make a modal view controller's presenter do something when the MVC is done? moonman239 iPhone/iPad Programming 5 Mar 4, 2014 02:07 PM
How to create a Modal View Programmatically (and dismiss it) roeik iPhone/iPad Programming 10 Aug 15, 2012 02:36 PM
Whats Wrong With My Code? (Presenting Modal View) loon3y iPhone/iPad Programming 2 Jun 14, 2012 03:22 PM

Forum Jump

All times are GMT -5. The time now is 09:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC