I'm trying to work on a simple login application which on successful login displays a menu page. On the action sheet of menu page, we have an option of looking at all the users logged in that phone and clicking on any user, it should do some login processing and direct to menu page again. This is how the workflow should go on.
Below is the image that explains it.
All the controllers are connected to segues except for accounts controller and middle controller. Navigation between those two is done using pushViewController as I had to pass some info from accounts controller(table view controller with list of all users) to middle Controller.
MiddleController *maController = [[MiddleController alloc] init];
if (maController.view) {
maController.ma_userId = mo_userId; // Set the exposed property
maController.ma_password = mo_password;
[self.navigationController pushViewController:maController animated:YES];
Middle controller is doing all the process perfectly after getting the details. But directing to menu controller is where I'm facing the problem. If I use a segue between middle controller and menu controller an error is thrown saying no identifier with the name segueName found. But if I use a pushViewController then it is displaying a blank black screen. Can some help me to solve this.
This is how I'm pushing it:
MenuTableViewController *mapMenuTableviewController = [[MenuTableViewController alloc]init];
[self.navigationController pushViewController:mapMenuTableviewController animated:NO];
I've tried all the ways that are posted in previous SO questions, but nothing helped.
Thanks in advance
Try not to alloc-init, but instantiate it fom storyboard like this (you should add it a storyboard id)
YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"ViewController"];
And then push it.
You need to add storyboard id like this
And use like
UIViewController *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"ViewControllerID"];
Go to your storyboard, and set an identifier like this :
Now, in your view controller, do this :
YourViewController *viewController = [[UIStoryboard storyboardWithName:#"<your storyboard name>" bundle:nil] instantiateViewControllerWithIdentifier:#"myViewControllerID"];
[self.navigationController pushViewController:viewController animated:NO];
UPDATE -
Push you Accounts view controller and Middle view controller the way i told before.
Then, when your processing is done in the middle controller, just do this :
[[self presentingViewController]presentingViewController]dismissViewControllerAnimated:NO completion:nil];
Add storyboard Id to yput interface builder "SendSMSViewController" and call below code.
let SendSmsVC = self.storyboard?.instantiateViewControllerWithIdentifier("SendSMSViewController") as! SendSMSViewController
self.navigationController?.pushViewController(SendSmsVC, animated: true)
Plz use this code you will go to MenuTableViewController.
for (UIViewController *controller in self.navigationController.viewControllers)
{
if ([controller isKindOfClass:[MenuTableViewController class]])
{
[self.navigationController popToViewController:controller animated:YES];
break;
}
}
Related
I have Collection View Controller PatientList -> on selection of cell navigates to PatientdetailView -> on click of button navigates to startDignosisView. This is Navigation controller stack. Now from Patient List I have button "ADD" that navigates to AddpatientView, from where I have to navigate to StartdignosisView without disturbing Navigation stack. How can I do it?
for (UIViewController *controller in self.navigationController.viewControllers)
{
if ([controller isKindOfClass:[NeededViewController class]])
{
[self.navigationController popToViewController:controller
animated:YES];
break;
}
}
if let viewControllers = self.navigationController?.viewControllers {
var newStack: [UIViewController] = []
for viewController in viewControllers {
newStack.append(viewController)
if viewController is StartdignosisView {
break
}
}
self.navigationController?.viewControllers = newStack
}
try like this:
some *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"some identifier you add to a vc in the storyboard"];
[self.navigationController pushViewController:vc animated:YES];
Just set the identifier to the storyboard for that view controller.
If you are not using storyboard then follow the below steps:
See if you Add Patient and then directly navigate to StartDignosisVC then you will not be able to pop to PatientDetailVC
You can do any one from these two:
First:
Try to present your AddPatientVC, add new and then dismiss it and follow your old stack path.
Second:
One ADD button action instantiate your AddpatientView like this:
AddPatientVC *obj = [storyboard instantiateViewControllerWithIdentifier:#"AddPatientVC"];
And similarly navigate to StartdignosisView with setting a flag that you are coming from AddPatientVC:
StartDignosisVC *obj = [storyboard instantiateViewControllerWithIdentifier:#"StartDignosisVC"];
obj.isFromAddPatientView = true
When you press Back button from StartDignosisVC then check if you came from AddPatientVC to directly pop it to Patient list.
If you are using storyboard then you can do the following see attached screen shot:
Thanks Mayank for your answer: following code worked in my case.
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
I have been searching around about this problem, but haven't got any answer yet. My problem is: I have a push button that when clicked will push to another view.
Here is how I push it:
ViewController *vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]
instantiateViewControllerWithIdentifier:#"Main_View"];
[self.navigationController pushViewController:vc animated:YES];
The ViewController vc is the view that I pushed. So in the new view, there is a Back button that can drop the current view and comeback to the old view. When I click the push button, the vc been load again from allover.
How can I make the instance of vc stay in memory, so when I go back to old view and come to vc again, it doesn't need to reload again?
I guess it is something related to navigationController stack, but don't know how to do that.
Thanks
Just keep a ViewController instance as property in your first ViewController
#property (strong,nonatomic)ViewController * vc;
Then when push it,check if it is in memory
if (self.vc == nil) {
self.vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]
instantiateViewControllerWithIdentifier:#"Main_View"];
}
[self.navigationController pushViewController:self.vc animated:YES];
Are you using a UINavigationController? If so, can call the following line of code in you back button 'IBAction':
[self.navigationController popViewControllerAnimated:YES];
If you really need to keep a instance of the view controller, do what Leo suggested.
I'm using SWRevealViewController to build a sliding menu. Before accessing the menu, a login view is displayed to allow the user login. Now i want to let the user disconnect and display the login view again. My question is how to pop the SWRevealViewController.
code that provides access to application after login is:
MainViewController *vMainMenu = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
vMainMenu.strURL = URL;
LeftMenu *vLeftMenu = [[LeftMenu alloc] initWithNibName:#"LeftMenu" bundle:nil];
UINavigationController *principalNavController = [[UINavigationController alloc] initWithRootViewController:vMainMenu];
UINavigationController *rearNavController = [[UINavigationController alloc] initWithRootViewController:vLeftMenu];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavController frontViewController:principalNavController];
mainRevealController.delegate = self;
self.viewController = mainRevealController;
principalNavController.navigationBar.hidden = YES;
rearNavController.navigationBar.hidden = YES;
self.window.rootViewController = self.viewController;
This solution is not working:
[self.revealViewController.navigationController popViewControllerAnimated:YES];
Splash *vSplash = [[Splash alloc] initWithNibName:#"Splash" bundle:nil];
[self.navigationController pushViewController:vSplash animated:YES];
Can you help me please
Thank you.
You can't go back to your LoginViewController by pop. You can add PresentViewController without animation to do this.
Splash *vSplash = [[Splash alloc] initWithNibName:#"Splash" bundle:nil];
[self presentViewController: vSplash animated:NO completion:nil];
I had the same issue. I have implemented several storyboards.
let storyboard = UIStoryboard(name: "Login", bundle: nil)
let startcontroller = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as UIViewController
window?.rootViewController = startcontroller
With this snippet you can access the right View Controller.
You can use an "Unwinding Segue". The unwinding segue is like a regular segue which goes back instead of forward.
First, go to the Login View Controller and add the following method:
-(IBAction)unwindToLoginScreen:(UIStoryboardSegue *)segue {
}
The method may be empty and it can have any name; it is good to use descriptive names because you might have many unwind segues on your code and it will be useful to be able to distinguish between them.
This unwind method will act as a global constant that will be visible to all View Controllers on the storyboard.
Now, on each view controller that should be able to return to the Login Screen you create a Unwind Segue. You can do this on the Storyboard:
Select the View Controller you want; on the top bar you should see three buttons, one representing the View Controller, another representing the First Responder and another representing an Exit.
Ctrl+Drag from the View Controller button to the Exit button. A context menu will appear and will list all visible unwind methods you created on your storyboard.
On the Document Outline, an "Unwind segue" will appear for the view controller. You can add an identifier to that segue (such as "Login" in your case). Then you call performSegueWithIdentifier. Select the one you created on your Login view controller.
Doing this, the complete stack between the view controller and the login view controller will be unwinded. That is, all view controllers stacked above the Login view controller will be popped.
You can also use prepareForSegue for the unwind segues the same way you would use them for regular segues. And you can add code to the -(IBAction) method if you want to do something as a result to the segue.
I am using storyboard in my app, :
I have Button in my View, On click of button i want to navigate to new View
But when i click on button nothing happens,
Here is my Code:
- (IBAction)JoinClicked:(id)sender{
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];
}
Where i am doing mistake , please help.
Thanks in advance.
Set storyboard id of view controller in story board in identity inspector
Make a reference to your storyboard like
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
then to your controller
YourController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YourController"];// storyboardId
[self.navigationController pushViewController:vc animated:YES];
and you can also make segue and do
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:sender/nil];
use this one :
- (IBAction)JoinClicked:(id)sender{
[self performSegueWithIdentifier: #"JoinWithIdentifier" sender: self];
}
and add segue in storyborad like
Make an identifier for your push-segue in storyboard.
then use
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:nil];
When using story boards you should use segues for as much navigation as possible.
Your code seems fine, please verify your outlets correctly configured or not in xib or storyboard.
Edit:
You are using storyboard and wants the xib file to get pushed onto your view controller if I am not wrong, you can drag another view controller in storyboard and name it JoinWithViewController and push using segue on button click. That is much easier than what your trying to do here.
I've created a storyboard that has a UITabbarController all is working well but now I want to add some logic that determines which viewcontroller a particular tabbar button will display.
Example... if a customer has a valid subscription display viewcontroller one, if no subscription display viewcontroller two.
Is this possible using storyboards, I've looked at UITabBarDelegate and prepareForSegue but struggling to piece this together?
Are there any examples of how to do this sort of thing using StoryBoards?
Many thanks
You can set it like this:
if(hasSubscription)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
ViewController1* subsection = [storyboard instantiateViewControllerWithIdentifier:#"ViewController1"];
ViewController2* subsection1 = [storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[(UITabBarController*)self.window.rootViewController setViewControllers:[NSArray arrayWithObjects:subsection,subsection1, nil]];
}
If you want to add rootviewController according to the subscription then above answer given by soryngod is good one.
But if you want to open viewControllers after rootviewcontroller loaded, then at tabBarButton press perform following code:-
before this code, add yours viewControllerONE and viewControllerTWO to the rootViewController by segues as shown: . And give each segue an identifier in AttributeInspector, example "one" for viewControllerONE and "two" for viewControllerTWO.
then at tabBarButton action do the following:-
if(subscription)
[self performSegueWithIdentifier:#"one" sender:self];
else
[self performSegueWithIdentifier:#"two" sender:self];