Load an storyboard (UITableViewController) from ViewController - ios

I want to load an storyboard from a ViewController. Currently my code looks as follows:
- (IBAction)Button_Action:(id)sender
{
UIStoryboard * sb = [UIStoryboard storyboardWithName:#"AddReportView" bundle:nil];
AddReportViewVC * vc = [sb instantiateViewControllerWithIdentifier:#"AddReportView"];
[self.navigationController pushViewController:vc animated:true];
}
The view is pushed but I do not see my expected View Controller (which is a UITableViewController) instead I just see an empty gray view controller.

Remember that in both the identifier name and the storyboard name, capitalization matters. I've gotten this wrong so many times...

The problem was that a function of the generated code by xcode coused the table view controller to flush the content.

Related

Navigation View Controller from Subview

I have been working on this problem for a while and thought I would ask for some help. I have 3 view-controllers: 1 Navigation Controller, 1 Main controller and 1 detail view controller.
Within the main view controller, I have a series of subviews with buttons. Due to the class structure, however, I am unable to directly call self.storyboard to get the current storyboard object.
I have tried 2 different methods, a variety of ways, and am still unsuccessful. I posted my methods below and described what is and what is not happening in each segment. The overall goal is to present a child view controller (the detail view) by tapping a button in a subview, of which does not have access to the parent storyboard directly.
Method 1
//Instantiate the new view controller
ProfileViewViewController *tempViewToShow = [del.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:#"profile"];
// Pass data into the new view controller
tempViewToShow.thisUser = self.postUser;
// Output a simple log to ensure both were created
NSLog(#"Temp User Name: %#, Profile Desc: %#", [tempViewToShow.thisUser getFullName], tempViewToShow.description);
// Using the AppDelegate for the RootViewController, present the detail view
[UIApplication.sharedApplication.delegate.window.rootViewController presentViewController:tempViewToShow animated:YES completion:NULL];
Issues
The issue with this series is that the detail view does not carry the navigation controller (since it is not mentioned), however, this way still shows a full View Controller
Method 2
...
// Use the Delegate and the navigation controller to present the new view controller
[UIApplication.sharedApplication.delegate.window.rootViewController.navigationController presentViewController:tempViewToShow animated:YES completion:NULL];
Issues
Does not display anything
Method 3
// Use the recommended 'pushViewController' for the navigation controller to carry over
[UIApplication.sharedApplication.delegate.window.rootViewController.navigationController pushViewController:tempViewToShow animated:NO];
Issues
Does not display anything
En toto, how would I make this work? What lines would I modify and how? Thanks!
You can solve this issue like this:
ProfileViewViewController *tempViewToShow = [del.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:#"profile"];
UINavigationController *naviController = [[UINavigationController alloc] tempViewToShow];
And then do this :
[UIApplication.sharedApplication.delegate.window.rootViewController presentViewController:naviController animated:YES completion:NULL];
You can create instance of storyboard from storyboard name.once you have correct storyboard instance, get NavigationController from Its identifier, and detailviewController from its identifier. Push detailviewcontroller on Navigationviewcontroller.
get storyboard-- replace name of your storyboard in "MainSToryboard"
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:[NSBundle mainBundle]];
get instance of Navigationcontroller - replace identifier:
UINavigationController *navController =(UINavigationController *)
[storyboard instantiateViewControllerWithIdentifier:#"navcontroller"];
get detailviewconrtoller :
UIViewController *detailvc=
[storyboard instantiateViewControllerWithIdentifier:#"profile"];
Push detail on current navigationcontroller:
[navController pushViewController:detailvc animated:YES];
I found an alternate solution. The cause was because the incorrect view controller was being called by
UIApplication.sharedApplication.delegate.window.rootViewController.*
The workaround is:
In the primary view controller class, I passed the displayed viewcontroller into the delegate class. Then, from the child class I wanted to call, I referenced that view controller, and navigation controller, and it worked just fine. My final code is below:
// Create the detail View Controller
ProfileViewViewController *tempViewToShow = [del.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:#"profile"];
// Set the user variable in the detail view controller
tempViewToShow.thisUser = self.postUser;
// Push the view controller into the navigation controller
// Note that del.currentNav comes from this code:
/*
* In this class, create the delegate reference
* AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate]
*
* In the Delegate class, get the set the current navigation controller {let currentVC : UIViewController = passedInVC}
* self.currentNav = currentVC.navigationController;
*/
[del.currentNav pushViewController:tempViewToShow animated:YES];

Navigation between Controllers - Black Screens

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;
}
}

Unable to pushViewController iOS

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.

How to get out of a UIStoryboard initialized in code

I have a main container controller that initializes child view controllers.
I'm trying to learn to use UIStoryboards tho and I'm stumped as to how to get out of a storyboard.
Here's the flow:
Once I get to the end of a storyboard's scenes, how should I get out of storyboard and back to my container controller?
Should I keep a pointer to the storyboard? What would I do with it?
Should I keep a pointer to the initial view controller (which is the one I explicitly add as child)? It's .view won't be on screen at the end so I don't know what I would do with that either.
Try looping through the childViewControllers
for (UIViewController *vc in self.childViewControllers) {
// do something
}
What do you mean "out of a storyboard". You don't need to save a pointer to your storyboard as self.storyboard should work in most cases. If you use a UINavigationController as your entry point in your storyboard with your initial view controller as it's root view, all you have to do to get back to your initial controller is
[self.navigationController popToRootViewControllerAnimated:YES];
Also, you can get a reference to your storyboard like this as well:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];

navigation controller get me to tabbar controller in IOS

Well I have read those posts and tutorials but they made me more confused:
url 1
quest 1
quest 2
What i want is to do this:
At the beginning my app, has a table view. when I press a row, it should take me to another view which has tabs.
What I did so far was these:
1) Created a navigation controller , and there is my tableview. When I press a row, a single view opens. In that view (with its own .xib file) I added tab bars items.
You can see pictures here:
But now, I don't know how to make it when pressing a tab bar item, to open a new view. I am trying to embed my view in a controller but I cannot.
2) Then I tried this:
Having my navigation controller as before and I added in storyboard a tabbar controller like in that picture:
But I cannot connect them. My first view is class "SkiCenter" and code I am using is:
SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenter" bundle:[NSBundle mainBundle]];
myDetViewCont.ski_center=[centers objectAtIndex:indexPath.row];
[self.navigationController pushViewController:myDetViewCont animated:YES]; // "Pushing the controller on the screen"
[myDetViewCont release]; // releasing controller from the memory
myDetViewCont = nil;
and I get SIGBRT that says something about .nib file for "SkiCenter".
Can you suggest a sollution in either 1 or 2?
just to make it more clear:
Solution 1:
pressing the row gets me to a single uiview named skicentermain. I have added several tabbaritems but I do not know how to make them open new views.
Sollution 2:
Inserted a tabbar controller. Its first tab is SkiCenter. But when pressing the row, I get a sigbart error. it says something about the nib file of SkiCenter.
If you decide to use storyboard you can simply put an identifier to any view controller from attributes inspector and then instantiate it with its id.
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
[[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:#"ViewControllerID"] animated:YES];
It looks like your declaring your *myDetViewCont incorrectly. You called your nib SkiCenterMain, not SkiCenter. Also, what exactly is on SkiCenterMain? Is that a UITabBarController?
//SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenter" bundle:[NSBundle mainBundle]];
SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenterMain" bundle:[NSBundle mainBundle]];

Resources