I am testing this code.
NSString *storyBoardName = #"Main";
UIStoryboard *storyBoard =[UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UIViewController *VC =[storyBoard instantiateViewControllerWithIdentifier:#"T1"];
[self presentViewController:VC animated:NO completion:nil];
It works fine, but the button needs to be pressed twice for this code to work. Is there any possibility of changing it to require only one tap?
Related
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];
}
I change the view programmatically like that:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"edit"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:nil];
The problem is, that when I change the view, that the data are not completely loaded. How can I say, that it should wait, until the data is loaded?
I have this code in the viewDidFinishLaunchingWithOptions: method in my AppDelegate.m, where result is simply my HTTP GET request response, and my UITabBarViewController is manually set(with the pointer) to be the initial view controller.
All I'm trying to do is simply make my LoginHomeViewController the rootViewController on startup if the user is not logged in. What do I need to do to make this happen? Do I need to resign the TabBar's status as rootViewController?
if([result isEqualToString: #"log"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *ivcTabBar = [storyboard instantiateViewControllerWithIdentifier:#"TabBarControl"];
[(UITabBarController*)self.window.rootViewController presentViewController:ivcTabBar animated:NO completion:nil];
NSLog(#"It's hitting log");
}
else if([result isEqualToString: #"notlog"])
{
[(UITabBarController*)self.window resignFirstResponder];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *ivcLoginHome = [storyboard instantiateViewControllerWithIdentifier:#"LoginHomeStart"];
[(UINavigationController*)self.window.rootViewController presentViewController:ivcLoginHome animated:NO completion:nil];
NSLog(#"It's hitting notlog.");
}
bug: currently it is logging me in even when it hits notlog, and gives me the error in the debugger saying: Warning: Attempt to present UINavigationController on UITabBarController whose view is not in the window hierarchy!
EDIT: *Changed "notlog" code*
else if([result isEqualToString: #"notlog"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController *ivcTabBar = [storyboard instantiateViewControllerWithIdentifier:#"TabBarControl"];
UIViewController *vcLoginHome = [storyboard instantiateViewControllerWithIdentifier:#"LoginHome"];
[ivcTabBar presentViewController:vcLoginHome animated:NO completion:nil];
NSLog(#"It's hitting notlog.");
}
Present loginViewController on tabBarController
if([result isEqualToString: #"notlog"])
{
[tabBarCOntroller presentViewController:#"Your Login View Controller" animated:YES completion:nil];
}
and resign loginViewController from within, once logged in
I use two buttons on right UIBARBUTTON by writing code in the method[ViewDidLoad].
http://i.stack.imgur.com/VcOEW.png
http://i.stack.imgur.com/vG3eT.png
http://i.stack.imgur.com/f0xsB.png
I want to use +plus button to move to AddNameViewController but it results in a Fail[sigabrt].
http://i.stack.imgur.com/MBq2m.png
http://i.stack.imgur.com/Hdw8T.png
I think the error is in the following code.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
Change this:
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"]
For this:
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController"]
You need the name of the View Controller, not the file.
Like Antonio said, you need the correct identifier for your view controller. The reason it crashes is because you get a nil view controller pointer back from the instantiateViewControllerWithIdentifier: call and passing nil to presentViewController:animated:completion: causes your crash.
check this
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
and add identifier AddNameViewController in storyboard ID
Sorry, I did not check carefully before asking. Because I tried many ways to improve it. Although, I change AddNameViewController.m to AddNameViewController ,
It still show sigabrt.
I have multiple storyboards within my app. I want to pass an object when a new storyboard is opened.
I'am doing this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"SetupStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController* initialHelpView = [storyboard instantiateInitialViewController];
SetupViewController *setup = (SetupViewController*) [initialHelpView topViewController];
setup.data = self.data;
initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:initialHelpView animated:YES completion:nil];
But when the storyboard is presented the setup.data is nil in viewDidLoad, viewWillAppear etc of the SetupViewController...
Why is that?
I don't see anything wrong with this code. Problem may be elsewhere.