storyboard elements are not visible when using manual push navigation - ios

i am using manual navigation on button click from one viewcontroller to another
nextpage *np = [[nextpage alloc]init];
[self.navigationController pushviewController:np animated:YES];
I included nextpage class on the viewcontroller in storyboard. But in this case the elements added via drag and drop are not visible while if i add manual elements via code they are visible from nextpage on navigating. Please help !
and If I add navigation from a button through a storyboard, in that case both coded elements and storyboard elements are visible. !

Try this.
Pass a identifier to your view controller in storyboard.
nextpage *np = [self.storyboard instantiateViewControllerWithIdentifier:#"your identifier"];
[self.navigationController pushviewController:np animated:YES];

Content you've added in the storyboard will only appear if you load that view controller from the storyboard. By simply alloc/initing a new view controller you're losing all of the information you've added in the storyboard.
You can create a segue from a view controller to another one (i.e. not from a specific button) if you want to manually push, just use performSegueWithIdentifier, or you can add an identifier to the view controller and use instantiateViewControllerWithIdentifier to create your VC from the storyboard.

first of all give storyboard id to viewcontroller then add following code
Nextpage *nextPage = [self.storyboard instantiateViewControllerWithIdentifier:#"NextpageIdentifier"];
[self.navigationController pushviewController:nextPage animated:YES];

Related

Segue between two tabbarcontrollers

We have redesigned our application to use a Tabbarcontroller as the main view. There is one instance where we need to display a record with enough data that it's also broken out into a tabbarcontroller. Previously we did our segue as showing below. I'm not sure what needs to change to segue between two tabbarcontrollers
SelectProvidersView *view = [[self storyboard] instantiateViewControllerWithIdentifier:#"careTeamView"];
view.careProviders = self.selectedPatient.careProviders;
[self.navigationController pushViewController:view animated:YES];
I'm guessing it's because I'm inside a tab controller instead of a navigation controller, I just don't know how this should be changed.
Don't use segue to switch between tabBarControllers. Use [(UITabBarController*)self.navigationController.topViewController setSelectedIndex:index]; to manually switch to the viewController you want

Push view of storyboard in accessorybutton tapped

I have storyboard named "MainStoryboard_iPhone.storyboard" and it has 2 views. The first view has a table cell with disclosure button. I can drag drop the table cell to other view and show the view, but I need to do it programmatically only when user click on accessory button without using segue. The name of 2 views are RootViewController and ProviderLookupViewController. Currently I have tried this code but doesnt work, it throws error when I click on the accessory button on the cell. Commented lines are the other things that I tried
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
bundle:nil];
// ProviderLookupViewController* vc = [sb instantiateViewControllerWithIdentifier:#"ProviderLookupViewController"];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"ProviderLookupViewController"];
[self presentModalViewController:vc animated:YES];
//[self.navigationController pushViewController:vc animated:YES];
}
If I am correct:
1) From your question it seems that you have a story board with two view controller, the first one is a UITableViewController and the other a subclass of UIViewController.
2) You want to present the second view when the user clicks the disclosure button.
Given that you use a storyboard instead of nib files, I recommend that you use a segue, it will solve you problem without writing code.
A table view cell can have two segues, one if you select the cell and another if you select the accesory button. Control drag from from the accessory button to the second view controller instead of doing the control drag from the cell and when the menu appears you have to select an option below Accesory action instead of below Selection Segue
The prototype cell of the table view has to have the disclosure accessory enable. Do it from the utilities pane (the right one). Accessory can't be none do this. In the picture accessoy is Detail disclosure.
The utilities pane also let's you do the segue. Use accessory action, though, teh picture is from one of my projects.
First give storyboard id as ProviderLookupViewController in your scenario and tick use storyboard Id then
ProviderLookupViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"ProviderLookupViewController"];
[self presentModalViewController:vc animated:YES];
Note:ProviderLookupViewController is your identifier.
Create a segue in IB from one view controller to another. Add some identificator to segue and just use
[self performSegueWithIdentifier:#"SomeSegueName" sender:someObject];

Load view when button is clicked in Xcodes Storyboard

I just started to use Storyboard in Xcode. I have a starting view that has some buttons inside. Is there a way to load a special view when a button is clicked?
I only found this workaround:
-(IBAction)loadRegistration:(id)sender {
// load registration controller
UIStoryboard *storyboard = self.storyboard;
RegisterController *svc = [storyboard instantiateViewControllerWithIdentifier:#"RegisterController"];
[self presentViewController:svc animated:YES completion:nil];
}
You don't need any code to load a new view. You just control-drag from the button to the controller you want to present, and choose the segue type. If the controller with the button is in a navigation controller you can choose push or modal, if it's not, then you want to choose modal.
The way you did it seems ok. You can also connect the current View Controller to the one you want to present with a segue in the Interface Builder (ctrl + drag). When the button is tapped, you would call [self performSegueWithIdentifier:#"segue identifier"];. Of course, you set the id of the segue in the IB.
Even more simpler would be to connect the button with the new View Controller in IB (also ctrl+drag). This way you won't even need the IBAction.

xcode 4.2 storyboard identifier

I'm writing an app in which I add some buttons to my view (mainView) by code. When the user taps on this buttons I want a new view (resultView) to show.
I have both of this views in my storyboard, but since there is no button on my mainView that is in storyboard I can't link the mainView and resultView to each other using storyboard. Everything must be done by code.
I want to know how I can link my two views by code and define an identifier for that link.
Thanks,
To switch the view controller programmatically, you have to set a identifier in the attribute inspector at section "View Controller". After that, you can just use the value inside your code. Here i used the identifier "Menu".
UIStoryboard *storyboard = self.storyboard;
MenuTableViewController *mtvc = [storyboard instantiateViewControllerWithIdentifier:#"Menu"];
[self presentViewController: mtvc animated:YES completion:nil];
There is also a description in the documentation, just look for
Instantiating a Storyboard’s View Controller Programmatically
Give the segue between the two an identifier in the Attribute Inspector in IB, then on your button press event call [self performSegueWithIdentifier:#"MySegueIdentifier" sender:theButton]

IOS Switch view and storyboard not works

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.

Resources