I am developing one iPad application using storyboard. In my application i have 2 view controllers(First view controller and Modal view controller). In my first view controller I have one table view with cell containing one button. If I click the button in each cell I need to go to modal view controller. I connected the modal view controller and button by using a segue. Segue is working perfectly when style is modal but I need style Popover. When I am trying to change the segue style popover the storyboard error occurs and compilation failed comes. How can I solve this issue.
Follow the steps in the image. hope I will help you.
If the error is "Couldn't compile connection..." the problem is how XCode handles an outlet inside a dynamic table cell view.
I suggest you 2 alternatives:
1) The error doesn't come if you can use a "static" table view, in this way the table view must live inside a UITableViewController.
2) If you need a dynamic table, subclass the cell view and in your class (say MyUITableCellView) put an outlet:
#property (weak, nonatomic) IBOutlet UIButton *segueButton;
Then in your storyboard create an outlet from the prototype cell (of class MyUITableCellView) to the button inside the cell (do not create the segue in the storyboard, create only the destination view controller).
Then in the "cellForRowAtIndexPath" do the following:
MyUITableCellView *cell = (MyUITableCellView*)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
/* IMP: Here you should check if button has already this action (reused) */
[cell.segueButton addTarget:self action:#selector(showPopover:) forControlEvents:UIControlEventTouchUpInside];
and then add the action:
- (void)showPopover:(UIButton*)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *secondVC = [storyboard instantiateViewControllerWithIdentifier:#"secondVC"]; // this is the storyboard id
self.popover = [[UIPopoverController alloc] initWithContentViewController:secondVC];
CGRect fromRect = [self.view convertRect:sender.frame fromView:sender.superview];
[self.popover presentPopoverFromRect:fromRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Hope this has helped.
Have you included the <UIPopoverControllerDelegate> and implemented it? That's easy to forget the first times.
May be you might have not connected the Anchor, put UIView in your Viewcontroller view somewhere with background colour clear and set Anchor point of the Segue to that view.....
Related
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];
I've been tracking along with an iPad app using storyboards, and I've been stuck on this for days. How can I initiate a popover segue by selecting a cell in a collection view? The main problem is getting past the error that the popover must be anchored to a view.
The approach seems to be putting a dummy popoverAnchorButton (hidden, disabled) in the view, create a segue from it to the popover view in the storyboard, position it in didSelectItemAtIndexPath, and then [self performSegue]. Code looks like this:
- (IBAction)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
CGRect anchorRect = CGRectMake(cell.center.x, cell.center.y, 1.0f, 1.0f);
self.popoverAnchorButton.frame = anchorRect;
[self performSegueWithIdentifier:#"popoverSegue" sender:self];
}
This works elsewhere in the app in a table view, because the storyboard lets me drop a button in the view, to use as an anchor point. But Xcode doesn't let me drop a button or any other suitable view into the collection view in the storyboard, so I can't create the segue. Creating the button programmatically is no help, because I can't build a UIStoryboardSegue from it, and any manual segue from the controller gives the same error about lacking an anchor point. Any ideas?
I think another path could be to skip segues and instantiate the popover view controller programmatically, but the roadblock here is an error stemming from the fact that the popover view I create (since I'm using storyboards) has no xib. Do I have to create a separate xib file just for this popover view? Is that the only option?
If you are interested in getting the CGRect of the currently selected cell in the collection view you might use:
CGRect rect = [collectionView layoutAttributesForItemAtIndexPath:indexPath].frame;
And after that you can display your popover from that rect using presentPopoverFromRect:inView:permittedArrowDirections:animated: of your UIPopoverController.
And yes, you can always dynamically load a VC from your storyboard if it has a storyboard identifier associated to it:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:#"YourIdentifier"];
In case you are calling the code from a VC loaded from storyboard itself, instead you can use:
UIViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"YourIdentifier"];
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];
hi I have a uicollectionview controller with two buttons ,when i click the first button it directly opens uitableview controller(with 2 button) and when i click the second button i want uicollectionview controller to show? how can i do this in storyboard?
i tried this code inside one button but its throwing one exception like "Nib file not found"
table *listview=[[table alloc]initWithNibName:#"listview" bundle:nil];
[self.navigationController pushViewController:listview animated:NO];
{list view is the uitableviewcontroller name ,i assigned this name on uitableviewcontroller title property in right panel of xcode}
"Nib file not found" error makes me reckon that you haven't spelled the .xib's name correctly.
Lets say you have your controller you want to push to.
TableViewController.h
TableViewController.m
And a corresponding xib thats linked with TableViewController.h. (view, IBOutlets, etc).
TableView.xib
Now in your main ViewController we push to TableViewController
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableView" bundle:nil];
[self.navigationController pushViewController:controller animated:NO];
Hope this helps.
BooRanger
We can use Story board identifier for moving from uicollectionviewcontroller to uitableviewcontroller
table *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"list"];
[self presentViewController:vc animated:NO completion:nil];
Its working fine
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.