I'm having a weird reaction in 1 of my view when swipe to back.
It did not go back to my previous page but other pages does not have this issue. Also, it perform the previous page viewWillAppear code after the swipe.
I did not set any custom back buttons for the views but it is having different effect.
--Edit--
In my previous page that call the affecting page
ViewControllerA *view = [[ViewControllerA alloc] initWithNibName:#"ViewControllerA" bundle:nil];
[self.navigationController pushViewController:view animated:YES];
In my affecting page I only declare viewDidLoad function.
All my navigation for other classes is using the above calling.
By normal clicking the back action at the navigation bar, it will go back to the previous page normally.
--Edit 2--
My current setup is ViewA > ViewB > ViewC where ViewC is where the bug is happening.
At ViewB when I swipe at the edge, it can go back to ViewA.
At ViewC when I swipe at the edge, viewWillAppear in ViewB called but ViewB is not shown.
Tried putting #kaushal answer
if ([self respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate; //check UIGestureRecognizerDelegate delegate set properly.
}
in both ViewB and ViewC but it did not trigger.
--Edit 3--
I tested my other features flow and it seems that some have this same problem upon entering the third view and some is on the forth view.
In ViewDidAppear: use this code :
if ([self respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate; //check UIGestureRecognizerDelegate delegate set properly.
}
And check UIGestureRecognizerDelegate is not nil.
Related
I have two frame in ios, let's say View1 and View2. View1 contains a table view. When you tap a cell you're being redirected to View2 with a detail of what you tapped.
View1 is connected to a tabbar button, but if i tap the button after i went to View2, i'm returned to View2 and not View1, so i put inside View2 this code:
-(void) viewWillDisappear:(BOOL)animated{
[self.navigationController popViewControllerAnimated:NO];
}
That is, when View2 disappear pop to View1, so in case i return back, using tabbar button i will be presented with View1
So far, so good.
Now, inside View2 there is a link presenting a MFMailComposeController so that you can send a mail. When i get back from mailing, the app crashes. It's totally right for viewWillDisappear is not distinguishing if View2 is disappearing for you're setting a mail or for you navigated to another View and the come back through tabbar.
So, there is a way to distinguish if View2 is being presented for a tabbar button is being pressed or anything else happened?
You can check self.tabBarController.selectedIndex inside viewDidDisappear. If the index is same as index of the view controller, then view controller need not be popped. When you switch tabs, the selectedIndex changes, so the view controller has to be popped.
-(void) viewDidDisappear:(BOOL)animated {
if (self.tabBarController.selectedIndex != correctIndex )
{
[self.navigationController popViewControllerAnimated:NO];
}
}
I've got a UINavigationController that can pop to multiple VC's. I want to disallow the 'slide to pop' slide animation if the VC to pop to is of a certain class. How do I do that?
Disabling the slide animation for the entire navigationcontroller can be done like this:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
But I want that only to be true if the destination is of a certain class.
I haven't tried this but the following should work:
UINavigationController has the interactivePopGestureRecognizer property.
In the viewDidAppear method of the view controller that you don't want to allow the "slide to pop", do:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
Then in the same view controller's viewDidDisappear method, call:
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
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.
Let me explain. I have multiple UIViewControllers. On my MainPageController, I have 3 UIViews. Let's enumerate it this way: the first UIView is called LoginView, the second is called HomeView and the other one is called RegView. Now in HomeView, there are multiple buttons that will lead to other UIViewControllers. For example, one button will lead to StoreController. Now if I am inside StoreController and I want to go back to MainPageController, I simply call:
[self dismissModalViewControllerAnimated:YES completion:nil]
This will send me back to the HomeView.
That is good. However, inside the StoreController, there are buttons which will supposedly direct me to LoginView or RegView, whichever button was tapped. The problem is when the method [self dismissModalViewControllerAnimated:YES completion:nil], it only take me back to HomeView, no matter which button I pressed.
So how will I display the right UIView once the dismissModalViewControllerAnimated is called?
EDIT:
This is how I show the UIViews:
-(void)viewDidLoad
{
//Initialize the views here...
}
-(void)showViewByTag:(NSInteger)tag
{
if (tag == 1)
{
[self.view addSubview:loginView];
}
else if (tag == 2)
{
[self.view addSubview:homeView];
}
else
{
[self.view addSubview:regView];
}
}
Now I call the method showViewByTag: somewhere in my code to display the views.
What you could try and do is following: before calling [self dismissModalViewControllerAnimated:YES completion:nil] (and thus go back to your home view), change the view currently displayed in your MainPageController:
[(MainPageController*)self.presentingViewController showViewByTag:desiredViewTag];
[self dismissModalViewControllerAnimated:YES...];
If you are worried at the cast and you foresee that self.presentingViewController might be not of MainPageController type on some occasions, then you can check explicitly for its type:
if ([self.presentingViewController isKindOf:[MainPageController class]])
[(MainPageController*)self.presentingViewController showViewByTag:desiredViewTag];
[self dismissModalViewControllerAnimated:YES...];
For this to compile, MainPageController.h must be imported in your modal controller class.
dismissModalViewController will always bring back the viewController which presented it ,and that can be only one,so the ideal way would be to tell the navigationController to initWith your desired viewController..
eg on regButton click in the presented modalview
RegViewController *regViewController = [[RegViewController alloc]initWithNibNam:#"RegViewController" bundle:nil];
[self.navigationController initWithRootViewController:regViewController];
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];
}