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]];
Related
I added a Navigation Controller to my storyboard and it appears like so:
Now in the table view controller, I gave the TableViewController a storyboard id and class to a TableViewController Controller
When I run my app, I don't see the Navigation Bar at the top. This has been extremely frustrating and can't find a solution anywhere. PLEASE HELP
To get to the scene, someone clicks a button and this code runs and it goes to my Table View Controller:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
LHFileBrowser *LHFileBrowser = [storyBoard instantiateViewControllerWithIdentifier:#"FileBrowser"];
[self.navigationController pushViewController:LHFileBrowser animated:YES];
[self presentViewController:LHFileBrowser animated:YES completion:nil];
The error is in your code.
If you want to (modally) present a view controller when the user presses a button, you need to present the navigation controller (which will contain the table view controller), not the table view controller itself.
Right now, you're presenting the view controller, which won't show it being embedded in a navigation controller.
Also, you're mixing up two different approaches, by trying to push a view controller onto a navigation controller stack, and also presenting the view controller.
Code Sample:
Here's what you apparently mean to do:
UIStoryboard *storyboard = self.storyboard;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"MyNavigationControllerID"];
LHFileBrowser *rootViewController = [navigationController topViewController];
// Configure your LHFileBrowser view controller here.
rootViewController.someProperty = ...;
// Modally present the embedded view controller
[self presentViewController:navigationController animated:YES completion:nil];
If you want to change the presentation or transition style, you can set those details in your storyboard.
You didn't explain why you had to programmatically add buttons, but Storyboard segues would have instantiated and presented an embedded view controller for you, without you having to have done it in code.
The more you can do in Storyboard, the less code you have to maintain, support, and update, and the more likely your app will still work properly when a new SDK is released.
Update:
The better way to do this is to let Storyboard do it for you, by adding a segue from the button to the navigation controller that you want to present.
In my app, I dynamically load a set of images, and when a user taps on an image, it opens up a new ViewController (MediaPreview) that opens up a large preview of the image.
I create the MediaPreview controller as follows:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
mediaPreviewVC = (MediaPreviewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MediaPreviewViewController"];
mediaPreviewVC.selectedImageURL = [NSString stringWithFormat:#"%#",gestureRecognizer.view.tag];
navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
[self presentViewController:navigationController animated:YES completion:nil];
This creates a ViewController that looks like this:
However, the bottom navigation bar appears to be missing, which is outlined in my storyboard:
How can I ensure that the bottom navigation bar buttons appear in my view?
You are creating the navigation controller out of whole cloth:
navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
alloc-init means "make me a completely fresh, separate, generic one". Thus, navigationController is not the navigation controller in your storyboard. It's a completely new and different navigation controller. Thus, what's in your storyboard is irrelevant.
If you wanted the navigation controller from your storyboard, you needed to instantiate the navigation controller from the storyboard. Or, if you're doing this intentionally, then the bottom bar won't be visible unless you explicitly make it visible, because by default it isn't (it's obvious how to make it visible explicitly).
But then in that case, if you meant to pull it out of the storyboard, then your whole code is probably wrong, because the one in the storyboard probably already has the correct root view controller as well.
I am trying to accomplish the following:
What I would like to do is:
1.) When the user clicks on a button in UIViewController, it will retrieve a list of items.
2.) The items will then be displayed in UITableView.
3.) Lastly the number of items will be displayed on the third view (not initiated by UITableView)
All the above I manage, except that I would like to wrap all these controllers in a customized tab bar controller. But the data is not being passed from the UIViewController to the UITableView or the other View. I am using Storyboard, I hooked up tab bar controller and the other 3 controllers there as view controllers. I have tried instantiating UITableView and the UIView controllers using UIStoryboard method and creating instances of these controllers and send the data to them, the controllers are shown in tab bar controller, but data is not. I am not using Segue, by the way. Am I missing something here?
Thanks.
CODE:
UITabBarController tabBarController = (UITabBarController) self.window.rootViewController;
UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
mainViewController *mainController = (mainViewController*)[storyboard1 instantiateViewControllerWithIdentifier:#"mainController"];
UIStoryboard *storyboard2 = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
tableViewController *tableview = (tableViewController*)[storyboard2 instantiateViewControllerWithIdentifier:#"tableviewController"];
UIStoryboard *storyboard4 = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
resultController *mapView = (resultController*)[storyboard4 instantiateViewControllerWithIdentifier:#"resultView"];</code>
I have tried also creating the UI Table View and the result view controller in MainViewController and pass data to them (before they are even displayed), but no data is ever present when these controllers are displayed. I made sure I alloc and init these controllers properly and NSLog shows that the instance methods in these controllers are called, but still no data is shown, even though the controllers are displayed in tab bar view controller, when they are displayed.
UPDATE 2:
Now I am trying to do the following:
self.tableviewController = [self.tabBarController.viewControllers objectAtIndex:1];
self.resultViewController = [self.tabBarController.viewControllers objectAtIndex:2];
And when I call these:
NSLog(#"%#", [self.tabBarController class]);
NSLog(#"%#", [self.tableViewController class]);
NSLog(#"%#", [self.resultViewController class]);
They are all null.
Basically, I have 3 View Controllers hooked up as "view controllers" using storyboard to a UITabbarController. The main view controller (at index 0 in UITabbarController), from which I call the above, simply has one UIButton. Once pressed it will fetch a list of strings and send it to the Table View (at index 1 in UITabbarController) and on the last View Controller (at index 2 in UITabbarController) it will show just the number of strings as a result, which it receives from the Main View Controller, not from Table View.
I am not using any UINavigationController in my set up.
I would like to be able to fire off Table View and the Result View Controller before they are even displayed by clicking on the bar item tab on UITabbarController. By firing off I mean the data will be sent over to Table View and Result View even though they are not yet displayed.
The code you present is unnecessary and wrong for what you want to achieve. (Usually you should have one instance of UIStoryboard.) Read the docs.
You do not write anything about how you try to achieve the communication between the view controllers. There are several methods. But use delegation. Read the docs.
If you answer to a comment you should use the # character followed by the SO user name so he is notified about your updates.
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.
I have a problem with switching views. I'm using a simulator with xcode 4.2
Storyboard contains:
NavigationController (initial view controller)
UIViewController which has relationship with the navigation controller
UIViewController (paired with my custom class: ViewEntryImageController) which hasn't got any relationship. Contains a button, a bottom toolbar with some toolbar button.
User come into the UIViewController, where he can see a ScrollView and in ScrollView some images.
Images has a gesture:
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(openEntryImage)];
[image addGestureRecognizer:recognizer];
[recognizer release];
The openEntryImage function:
(IBAction)openEntryImage
{
ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:nil bundle:nil];
controller.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}
When I try to tap the image, the openEntryImage works as well (the effect is correct), but I don't see my ViewEntryImageController view and my buttons, I'm only see a black window.
I try to put a NSLog line into the ViewEntryImageController viewDidLoad function, and it works, so what is the black window and where is my view controller?
When I try to use pushViewController, on the new view I found a navigation toolbar with a back button, but no other controls.
I tried another version, I created a UIViewController class, but now with a xib file. I used it instead of ViewEntryImageController and it works. Why?
I want to use this controller in storyboard too.
The ViewEntryImageController class by itself has no information about how to build the dialog. But you can instantiate your view controller on your own from the storyboard:
UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:#"StoryboardFileName" bundle:nil];
ViewEntryImageController *controller = (ViewEntryImageController *)[myStoryboard instantiateViewControllerWithIdentifier:#"ViewEntryImage"];
This assumes a storyboard name of StoryboardFileName and that the view entry image controller has an identifier of ViewEntryImage set in the view properties (Attributes inspector, section "View Controller").
Try it like this :
ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:#"ViewEntryImageController" bundle:nil];
If you don't use .nib names but rather use storyboards, it's a bit harder. Create a segue from the controller to the ViewEntryImageController controller by holding ctrl and dragging from one view to the other. Click this segue and give it an identifier.
Then use the [self performSegue:#"identifier"]; function to present the next view.