I wanted to be able to enter a view controller only if an entered password is correct.
i used the following code -
if(([input isEqual:#"12"]))
{
NSLog(#"change view controller");
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"secondViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
but when i enter , Xcode gave me a sigbrt error, so i added an all exception breakpoint, but it goes to main.m and says 'thread 1:break point 1.1'.
thank you for reading and if you know the answer please answer
SecondViewController *second=[self.storyboard instantiateViewControllerWithIdentifier:#"storyboardid"];
[self.navigationController presentViewController:second animated:YES completion:nil];
Related
I'm trying to call a controller, if has response error, and redirect the user for login controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"EventManagerStoryboard" bundle:[NSBundle mainBundle]];
LoginViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:#"loginID"];
[loginController viewDidLoad];
loginController.showOnlyLoginForm = YES;
[self presentViewController:loginController animated:YES completion:Nil];
and I facing this warning -
Attempt to present Attempt to present LoginViewController: 0x7fc958201130 on ProfileController: 0x7fc9583118e0 whose view is not in the window hierarchy!
Don't run this code in viewDidLoad try it in viewDidAppear
[self presentViewController:loginController animated:YES completion:Nil];
Edit:
use in appDelegate if you implement navigationController
[(UINavigationController *)self.window.rootViewController pushViewController:vc animated:YES];
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'm developing an application, and at some point I need a Modal ViewController to "become" the Root ViewController.
How can I dismiss the current rootController, and set my Modal as my new rootController?
First you have to set your root view controller nil.
[self.window setRootViewController:nil];
UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle: nil];
Nearbylocations *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"near"];
self.window.rootViewController=introViewController;
You can try below code..
[self dismissViewControllerAnimated:NO completion:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:modalviewref];
[self.navigationController presentViewController:navBar animated:YES completion:nil];
Hope it helps you..!
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.