Hi I'm trying navigate to view controller form the navigation view controller with connect using the objects
i want to do by programmatically but its not working its showing the black screen. Please tell me how to resolve this.
- (IBAction)reg:(id)sender {
pollpoliticalViewController *vc2 = [[pollpoliticalViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}
The above code i have used to navigate but its giving black color screen its not showing the view controller please tell me where I'm doing wrong.
Thanks.
Nothing is wrong with the above code.
As I understand what you are doing, you have a view controller class called pollpoliticalViewController. My first suggestion would be for you to look into the accepted coding style in Objective-C. You should always capitalise classes. In this instance the class should have been called 'PollPoliticalViewController`. Obviously this is not the source of the problem though.
The problem will be with the view controller itself. In the code for pollpoliticalViewController you are doing something wrong which is not displaying the view.
The view controller may actually be styled inside of a .xib file, in which case you should be initialising the view controller like this:
pollpoliticalViewController *pollVC = [[pollpoliticalViewController alloc] initWithNibName:#"pollpoliticalViewController" bundle:nil];
If the view controller is defined inside of a storyboard, you will have to give the view controller a 'Storyboard ID', for example; 'PollPoliticalVCID'. You then need to initialise it like this (assuming your storyboard is called "MainStoryboard":
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"PollPoliticalVCID"];
EDIT
The storyboard name is found when you open the storyboard, do not select any view controller. Open the Utilities side bar (on the right side of Xcode), select the first item, and you can find the name under Identity and Type. I have included an image.
Related
Ok, first let's name things:
I have a table view in my root view controller wich we'll call "HomeViewController". In that table view each cell tap will push a different view controller. This collection of view controllers we'll call "DetailViewControllers".
I am perfecly aware that I can make this work by simply loading and pushing each of the DetailViewControllers programmatically inside the didSelectRowAtIndexPath method. I want to do something different instead using storyboard and a prototype cell and I'm not succeeding, so I'm looking for some advice since I'm not too well versed in storyboards and segues.
The behavior I'm trying to achieve here is:
I'll have a segue from a prototype cell in the table view in my HomeViewController. That segue pushes a "base" view controller, from which every DetailViewController inherits. These view controllers don't have an assigned view controller in the storyboard either.
In the prepareForSegue method I want to cast the 'destinationViewController' to the 'right' class. The app crashes at that point saying it "Could not cast value of type 'BaseTestViewController' to 'TestViewController'.". Which is totally understandable.
So, my question is: is there a way to make a segue work like that?
You can't create segues programatically. Segues don't exist without a storyboard. You can just push to a view controller via loading a nib file.
Here's how you do it.
Let's say you have a nib file containing the layout of the view for the main view of your view controller. We'll name it "Test" for instance.
Go to that nib file, click file's owner.
Change class to the name of your view controller. In my case, I named it ViewController.
Right click on file's owner. Link the outlet of view of your view controller to the view in the nib file.
Then in the view controller where you want to transition to that view controller, you do it like this:
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"Test" bundle:[NSBundle mainBundle]];
[self presentViewController:controller animated:YES completion:nil];
It will present the view controller modally.
If you are embedding a navigation controller then you can do it like this:
[self.navigationController pushViewController:controller animated:YES];
Hope it helps.
Try like this without storyboard segue.
let objDestVC = self.storyboard.instantiateViewControllerWithIdentifier("DestVCStroyboardId") as! DestinationViewController
self.navigationController?.pushViewController(objDestVC, animated: true)
I need to create a modal "flow" within my app. It is made of two "scenes", these are both UITableViewController subclasses.
The user will be able to push and pop between these two table views.
At any point they will be able to press "Done" (in a nav bar) and dismiss the entire modal view to go back to where they were.
This whole modal flow needs to be accessible from several places in the app. I don't really want to create multiple modal segues to this.
My question is, creating this in a storyboard, would you create a whole new storyboard for this flow (I don't like this).
Would you just create multiple modal segues?
Should I create this flow in the same storyboard file but as a separate entity accessible by the identifier?
Or something else?
Sounds like it would be easier to use a single storyboard, but not create multiple segues everywhere. You can programmatically present the view controller pretty easily:
MyViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
// set any properties on vc here, if necessary to pass it any data
[self.window.rootViewController presentModalViewController:vc animated:YES];
You could place all this code in a helper method to reuse this code more easily, maybe a class method like this:
#interface MyViewController ...
+ (void)presentNewViewControllerModally;
...
#end
Tapping the done button:
[self.window.rootViewController dismissModalViewControllerAnimated:YES];
Note that if there's a good chance you'll never see this modal view controller, you could place that view controller in a separate xib file instead of in the storyboard, and I think that could make things more efficient (storyboard remains more lightweight). In this case, just replace the instantiteViewControllerWithIdentifier message above with:
[[MyViewController alloc] initWithNibName:#"SomeNib" bundle:nil];
...and the rest of the code is the same. I've used this technique for a "login" view controller that would only occasionally need to be presented.
and how do you create it? - the popup one in the middle
I would lie to use something like this for my game (in the main menu).
There is no type for UIViewController. There are different ways how you can present UIViewController.
iPad support following three type:
Full Screen
Page Sheet
From Sheet
Your image is showing third one UIModalPresentationFormSheet.
You can Find detail of how to use this three type of presentation at following app guide:
Presenting View Controllers from Other View Controllers.
That's the link to the documentation.
Presenting View Controllers from Other View Controllers
A modal view controller is a controller that can be presented on top of another one.
To create it, for example, you can just call presentViewController:animated:completion: method of the current view controller, passing in the view controller you want to present.
Since the interface you have uploaded contains a navigation bar that contains a close bar button item, you can simply wrap the controller you want to present in a navigation controller.
YourViewController *yourViewController = [[YourViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:yourViewController];
[self presentViewController:navigationController animated:YES completion: nil];
Otherwise, you can create a plain controller and use a UIToolBar.
Hope that helps.
P.S. The close button will not be there for free. You need to add it ;)
I think it would be much better to use a third party library instead of implementing it. There are many libraries that offer similar functionality.
UAModalPanel
MTPopupWindow
KGModal
If you do not want to use the above libraries, you can use UIModalPresentationFormSheet explained by Apple in this document: Presenting View Controllers from Other View Controllers
Hope this helps!
I'm running into trouble with what I think is a pretty basic task. Within peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: i want to show my own view rather than the standard person view. I'm using a Storyboard, but don't think I can simply manually segue to a window here so I'm thinking I need to create a new XIB with a View Controller in it. I'm setting the Class of the View Controller to my custom View Controller in IB. Then in peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: I'm doing:
MyVC *myVC = [[MyVc alloc] initWithNibName:#"XIBFileName" bundle:nil];
[self presentModalViewController:myVC animated:YES];
In my View Controller initWithNibName gets called, but not viewDidLoad. What am I doing wrong here?
Just try [peoplePickerVC presentModalViewController:myVC] instead of presenting from self.
The issue is that the peoplepickerviewcontroller will be in the top of the navigation stack. Becuase you wud've presented the peoplepicker from self. As this is the case, you wont be able to present/push from self as its not at the top of the navigation stack.
Otherwise once the peoplepicker has been poped, then you can further present from self.
I'm developing a little example for iPad from a UISplitView XCode Template. It's formed by a root controller which is shown in the left of the window and a detail view which is shown in the right.
What I want to achieve is very simple (at least I think so) but I can't find in the documentation the way to do it.
I'd like to substitute the root controller (which appears fixed in the left) with a new controller (for example as response to a event launched when you push a button). I've tried this:
ColorPicker *controlador = [[ColorPicker alloc] initWithNibName:nil bundle:nil];
[self.rootViewController presentModalViewController:controlador animated:YES];
[controlador release];
What happens with that is that the new pushed controller fills the entire window, whereas what I want is that appears fixed at the left with the two columns format that were at the beginning.
You need to set the modalPresentationStyle to an appropriate value,
controlador.modalPresentationStyle = UIModalPresentationCurrentContext;
UIModalPresentationCurrentContext instructs the view controller to appear modally within the frame of the rootViewController.
Use pushViewController:animated instead may fix this. About ModalViewController, check document http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html