Hi there, Now I'm trying to create a Pop-OverView using an Xcode
storyboard. Firstly, I have
rootViewController, UIViewController, and UITableViewController
I want the UIView to act as a page flip and the UITableView will show popOver under the navigationBar item controller.
For the UITableView, I want to make a Pop-Over under NavigationBar controller. The problem is, when I touch the Navigation item to show the UITableViewController, it shows correctly, but when I try to close the Pop-Over View, it won't close. And then, the navigation item doesn't work well. It shows multiple instances of popOverView when I touch it multiple times.
This doesn't seem to make sense to me. Can anyone help me out or tell me where to find documentation / tutorials on this?
UPDATE:
For the UIPopOverController, it seems to work well now, but it is still bugging me when I touch a Navigation Item multiple times. It will show multiple instances of PopOver. How can I handle it, so it will show only one instance?
I had the same problem and mostly found the solution here. Basically you change the action of the button each time it's pressed to either display or dismiss the popover. Here's the code I ended up with:
#interface FilterTableViewController : UITableViewController {
UIPopoverController *editPopover;
id saveEditSender;
id saveEditTarget;
SEL saveEditAction;
}
-(void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"EditFilterSegue"]){
// Save the edit button's info so we can restore it
saveEditAction = [sender action];
saveEditTarget = [sender target];
saveEditSender = sender;
// Change the edit button's target to us, and its action to dismiss the popover
[sender setAction:#selector(dismissPopover:)];
[sender setTarget:self];
// Save the popover controller and set ourselves as the its delegate so we can
// restore the button action when this popover is dismissed (this happens when the popover
// is dismissed by tapping outside the view, not by tapping the edit button again)
editPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
editPopover.delegate = (id <UIPopoverControllerDelegate>)self;
}
}
-(void)dismissPopover:(id)sender
{
// Restore the buttons actions before we dismiss the popover
[saveEditSender setAction:saveEditAction];
[saveEditSender setTarget:saveEditTarget];
[editPopover dismissPopoverAnimated:YES];
}
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
// A tap occurred outside of the popover.
// Restore the button actions before its dismissed.
[saveEditSender setAction:saveEditAction];
[saveEditSender setTarget:saveEditTarget];
return YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Before we navigate away from this view (the back button was pressed)
// remove the edit popover (if it exists).
[self dismissPopover:saveEditSender];
}
Related
Is there a way to summon a callout box on a button next to a textfield or inside the textfield?
Or is UIAlertView my only choice?
Edit: With my successful attempt at creating a UIPopoverController, is there a method to position the arrow so that it does not appear in the center?
I have successfully achieved my goal of creating a callout box as it appears in the image of my question. I'd like to thank Paul Cezanne for mentioning a solution for me to pursue. I guess the name (pop over/callout) is different if it is not displayed in a map view. Anyways, for future apple developers, here are the steps I took that answered my question:
Embed your first view controller with a navigation controller
Keep auto layout and size classes checked in the File Inspector tab on the right hand side in your main storyboard, because the pop over will just act as a push view if we shrink the view controller.
Add a second view controller (you do not need to create a header nor an implementation file)
Drag a button onto the first view controller (you do not need to create an IBAction)
Hold the control key and click and drag from your button on the first view controller to your second controller and the segue choices should appear
Select 'Present As Popover'
Don't forget to create an identifier for the segue
Now heading over to coding, here is the header file of the view controller:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIPopoverPresentationControllerDelegate>
#end
Here is the implementation file of the view controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Declare a string to identify the segue
NSString *identifier = segue.identifier;
// If the string matches the string inside #""
if ([identifier isEqualToString:#"popOverSegue"]) {
// Assign the view controller to a pointer
UIViewController *dvc = segue.destinationViewController;
// Identify that the view controller is to be a pop over presentation controller
UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
// Set the size of the view controller
// Width = 200
// Height = 200
dvc.preferredContentSize = CGSizeMake(200, 200);
// Have the pop over presentation controller point upwards
ppc.permittedArrowDirections = UIPopoverArrowDirectionUp;
if (ppc) {
ppc.delegate = self;
}
}
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
Build and Run and you should have a successful pop over controller app. Fin.
I have this problem:
I have two ViewControllers.
I am transitioning to the second view with Segue.
User enters his name on first view controller and taps on a button. If the text is nil, it should not show the second view controller. If some text is there on the text field - it has to show the next view controller.
I am checking the text length here below. As I have only one segue... I am not checking segue identifier.
And, on Storyboard, I have give modal transition CoverVertical. The animation is not working. View is just appearing. UIModalTransitionStyle also I tried. Still not working (on device and simulator)
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if(playerNameTextField.text.length == 0)
{
UIColor *tempColor=UIColorFromRGB(0xFF4981);
[self colorizeTextViewForAWhile:playerNameTextField withUIColor:tempColor animated:YES];
return NO;
}
return YES;
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"segueMoveToHome"])
{
ViewController *vc = (ViewController *)segue.destinationViewController;
vc.playerName=playerNameTextField.text;
}
}
Your code works perfectly. I just reproduced and I've got a transition with CoverVertical.
In Interface Builder, select the Storyboard Segue and be sure that you have:
I'm linking you a mini demo with your code that works.
I have removed the Identifier text and continued. As it was the only segue or any other reason... it was working. If I put the segue... it is not working. :| Not sure. But I have now my app working.
I have a table view with different types of table view cells in it. In one of the cells, there are two buttons, which load a view controller when pressed. I am using the following function to handle the button press:
- (IBAction)leftButtonPressed:(id)sender
{
// Getting the pressed button
UIButton *button = (UIButton*)sender;
// Getting the indexpath
NSIndexPath *indPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
// Loading the proper data from my datasource
NSArray *clickedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indPath.row];
[[SOEventManager sharedEventManager] setSelectedEvent:clickedEvent[0]];
// Everything working as it should up to this point
// Performing seque...
[self performSegueWithIdentifier:#"buttonSegue" sender:self];
}
My buttonSegue is supposed to push a new view controller. Somehow instead of pushing once, it appears to be pushing twice, so I get the following warning:
2013-11-27 01:48:30.894 Self-Ordering App[2081:70b] nested push animation can result in corrupted navigation bar
2013-11-27 01:48:31.570 Self-Ordering App[2081:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
In my case it leads to a crash, since there is an event in which I want the app to immediately pop the view controller so it an go back to my table view. I use an alertview for this and handle the event with the following:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
// ...
// Additional checking of button titles....
else if ([buttonTitle isEqualToString:NSLocalizedString(#"Vissza", nil)])
{
[self.navigationController popViewControllerAnimated:YES];
}
}
It might me interesting to note that I have an other segue from my "regular" table view cell, and in that case I use the prepareForSegue: method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"detailSegue"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SOEvent *selectedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indexPath.row];
[[SOEventManager sharedEventManager] setSelectedEvent:selectedEvent];
}
}
In this case the view controller gets pushed perfectly, and even popped immediately if that is required. I am testing this on iOS7 and Xcode 5. I haven't encountered a problem like this before, any help would be greatly appreciated.
Maybe you want to wire up your segues with View Controllers instead of UIButtons!
You should probably have the segues wired with some button like this:
But you should wire them with the view controllers instead:
Answer by can poyrazoğlu:
are you sure you've wired up the actions correctly in interface
builder? maybe you've wired the event for, say, both touch up inside
and touch down inside instead of just touch up inside. or maybe you've
also assigned the segue from both code and again in interface builder.
have you checked them? it's a common mistake. –
I was assigning the touch up inside actions for each button both the storyboard and my tableview's datasource methods.
Thank you for your quick help can poyrazoğlu!!
For Swift 3, xcode, and ios 9+, which is what I am using: Make sure you are drawing segue from your UIViewControllers and not buttons or other interfaces.
I had the same problem, and simply changing the start of the segue from the UIController instead of the button removed this bug.
I always get this issue when I have my buttons directly wired up to the destination view controller. You need to make sure that you first delete the old segue you made, then click on the present view controller (where you are coming from) and CTRL + click to destination controller.
This should fix it :)
I am pushing a viewController onto the UINavigationController with animation, and the controller being pushed on is basically doing something like:
--- app delegate:
[((UINavigationController *)window.rootViewController) pushViewController:initialController animated:YES];
--- initial controller:
- (void)viewDidLoad {
[super viewDidLoad];
if (self.shouldSkipThisController) {
SomeOtherViewController *someOther = [[SomeOtherViewController alloc] init];
[self.navigationController pushViewController:someOther animated:NO];
}
}
This is causing some CRAZY behavior which I don't understand at all. Basically, it seems like the navigation items set on SomeOtherViewController are being covered up by some strange other button that has the name of the title in a back button. It looks like although SomeOtherViewController is setting it's own left and right navigation items, they are covered up by the "default" back button--- and then if I tap on that back button, then just the navigation bar at the top animates-- and THEN SomeOtherViewController's navigation items are then there.
The only thing I could find that sort of worked was to either 1) not animate the push of the initial view controller in the app delegate, or 2) move the shouldSkipThisController condition into viewDidAppear: method.
However, neither of those options are ideal... Any help could be greatly appreciated.
I was wondering how I could use 1 button on my ToolBar to open and dismiss my UIPopOver. If I keep tapping the button right now, another PopOver overlaps the previous one. I want ONE button to be able to dismiss and open my PopOver. I tap once, it opens. I tap the button again, it dismisses. Please tell me how. Thanks
In your button tap action event:
if (myPopover.popoverVisible) //self.myPopover if using property
{
[myPopover dismissPopoverAnimated:YES];
return;
}
//continue code here to create/present your MyPopover…
Quick way to do it is to define a UIPopOverController property in your presenting view controller and use this property to instantiate your popover (and accompanying content view controller).
In your presenting view controller you'll need something like:
UIViewController *aViewController = [[UIViewController alloc]init];
self.popOverController = [[UIPopoverController alloc] initWithContentViewController:aViewController];
Then in your button's action to toggle the popOver it should do something like:
if(self.popOverController.popoverVisible) {
[self.popOverController dismissPopoverAnimated:YES];
} else { //Display the popover }
Hope that help