Multiple storyboards and view deallocation - ios

I developed an application using only one storyboard and towards the end, when my app grew to have some 80 views, working in the storyboard was extremely difficult.
After some clicks the storyboard became non responsive/sluggish and I had to restart the xcode to get things back to normal.
So this time I decided to use multiple storyboards but I have the following problem. When I switch from one storyboard to the other, views on the storyboard I am popping from are not deallocated. As a result instruments show a continuous increase in memory allocations which is not acceptable.
Anybody knows how to dealloc the view in the second storyboard when I move back to the first ?
Bellow are the two ways I use for navigation
With one storyboard
-(IBAction)goToVcSameStoryboard:(id)sender{
[self performSegueWithIdentifier:#"segue" sender:self];
}
-(IBAction)backSameStoryboard:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
With two storyboards
-(IBAction)goToVcDiffStoryboard:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard1" bundle:nil];
UIViewController *initialVC = [storyboard instantiateInitialViewController];
initialVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:initialVC animated:YES completion:nil];
}
-(IBAction)backDiffStoryboard:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UIViewController *initialVC = [storyboard instantiateInitialViewController];
initialVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:initialVC animated:YES completion:nil];
}

Related

Open Storyboard on top of previous view

I have created storyboard which I want to open on top of another view or in childView so that when I close or destroy this view of storyboard the earlier view on which the storyboard is opened remains the same.
When I run the following code:-
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[[UIApplication sharedApplication].keyWindow setRootViewController:detailViewController];
First, the storyboard opens but I don't know whether it opens on top of previous view or it destroys the previous view & then open.
Second, the functions needed on that storyboard runs automatically which is as I want but how these things are working.
If anyone can help me understand the above code and its working.
NOTE: I cannot call the earlier view again in same state because of some reason.
Thanks in Advance!!
Here you are setting root view controller
it will not keep your back screen as it is what you want
If you want to keep current screen and show other screen on that
you have two approaches
1) Present ViewController
2) Push View Controller
1) Present ViewController
for this you can present your screen on top of other screen which is visible
for example
- (IBAction)btnNextTapped:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[self presentViewController:detailViewController animated:true completion:nil]
}
2) Push View Controller
For that you need NavigationController and need to push your ViewController from current visible screen
i.e
[self.navigationController pushViewController:vc animated:true];
EDIT
as per discussion you need to find current top view controller then you should present it
Add this method below your method
- (UIViewController*) topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
And Replace this method with code
- (void)goToNewPage:(CDVInvokedUrlCommand*)command
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
ViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"neolick"];
[[self topMostController] presentViewController:detailViewController animated:true completion:nil];
}

Why UIModalPresentationPageSheet not working ... its always fullscreen

Here is the code snippet for presenting view controllers as Form sheet.Its not working
It always comes as full screen
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"ViewController2"];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:vc animated:YES completion:NULL];
I even tried ... preferred content size not works...
I think you are trying in iPhone.
Try this in iPad.
In iPhone its always full screen.
In iPad it will look as formsheet as per your expectation
If you want this to work in iPhone you have to try a third party library or do it yourself

Navigate in uiviewcontroller iOS

I have a problem in memory management, when navigate to specific UIViewController
Example:
I have 3 UIViewController and use Storyboard modal segue and I stay in the first and I need go to the number 3 directly
I use this code works fine, but when i need return to the 1 and I if repeat this code. I receive a memory warning and crash later.
This is my code:
go to view 3 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:#"Three"];
[self presentViewController:viewTree animated:YES completion:nil];
go to view 1 ->
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewOne = [storybord instantiateViewControllerWithIdentifier:#"One"];
[self presentViewController:viewOne animated:YES completion:nil];
You must be constantly be presenting each view controller over each other, which is raising the memory warning issue. To present ViewControllerThree use the following code in ViewControllerOne
#implementation ViewControllerOne
- (IBAction) goto3 {
UIStoryboard *storybord = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * viewTree = [storybord instantiateViewControllerWithIdentifier:#"Three"];
// Brings you to the third view controller.
[self presentViewController:viewTree animated:YES completion:nil];
}
#end
And then to go back to ViewControllerOne implement this code in ViewControllerThree
#implementation ViewControllerThree
-(IBAction) backTo1 {
// Dismisses the third view and brings you back to the first view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}

storyboard, self presentViewController, iOS 6, blank screen

I am using storyboards, I have one viewcontroller and on click I need to show another view controller modally. I am trying using this code
[self presentViewController:zoomV animated:YES completion:NULL];
I am coming up with a blank screen.
This is how I create
zViewController *zoomV = [[zViewController alloc] init];
[self presentViewController:zoomV animated:YES completion:NULL];
I tried researching this and some answers revolve around using storyboards and not having a rootviewcontroller associated. So what I have is in the initial scene I have a navigationController, and from there I drag to another Viewcontroller a relationship which defines it as a rootViewcontroller. Is that sufficient ? or is this irrelevant?
Since you have your zViewController in your storyboard, you should instantiate your zViewController using UIStoryboard instantiateViewControllerWithIdentifier:.
In your first view controller, instead of creating the zViewController using alloc/init do this, of course setting an identifier for your zViewController in your storyboard.
zViewController *zoomV = [self.storyboard instantiateViewControllerWithIdentifier:#"yourIdentifier"];
[self presentViewController:zoomV
animated:YES
completion:NULL];
Also you could accomplish the same using a segue and executing it directly, without the need of instantiating the zViewController, but is up to you.
As a second(small) comment, do not name classes starting with lowercase in ObjC :).
You may refer below snippet for story board:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];

Transition between two UIViewControllers with no animation

From my appDelegate I load the the homeScreen ViewController like this:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self.window setRootViewController:controller];
The app only ever then changes between my 'homeScreen' and 'PlayViewController' ViewControllers and that is done like this:
PlayViewControlller* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PlayViewController"];
[self presentModalViewController:vc animated:NO];
and this
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self presentModalViewController:controller animated:NO];
respectively.
This all works fine. I am able to switch between the viewcontrollers with uibuttons and the above code. However, I'm not sure what causes this, it happens after I've switched between the two viewcontrollers a few times, but the transition starts to get animated and they start twirling when switching.
Ok so I'm trying to narrow down the problem and see what's causing it. I think its the other animation blocks that I'm using in my app. But there's a lot there so don't know exactly what it is.
OK so I found the line of code that was causing this if anyone happens to find themselves in the same situation.
[UIView beginAnimations:#"Move" context:NULL];

Resources