Swift canEditRowAtIndexPath not working in UIPageViewController EZSwipeViewController - ios

I have the following scenario and need help in resolving a tricky situation in the scenario
There is an Xcode project and am using EzSwipeController for swipe (pagination effect) between three View Controllers at the moment.
In my first ViewController (this viewController is fetched from my custom dynamic framework as part of my requirement) -
Code to fetch ViewController:
userProfile.createProfileUI(userSession!) { result in
switch result {
case let .Success(profileViewController):
myDetailsVC = profileViewController //myDetailsVc is passed to EZSwipControllerDataSource array
default:
break
}
}
The other two ViewControllers are within my project storyboard
The Problem -
In the first ViewController, there is a tableView with canEditRowAtIndexPath enabled for few cells (phone numbers).
So when I try to swipe the row, the EZSwipeController responds first and
hence, I am not able to edit the row.
Here is what is happening - http://recordit.co/SOJgdeYchP
Here is what should happen - http://recordit.co/EBPSbjH31q
How do I handle this problem? Is there a way where I can override the default swipe controller action when I try to edit the row?
Please help!

Attach the swipe gesture recognizer to a parent in the hierarchy.
If you're using a UITableViewController, replace it with a UIViewController with a UITableView inside it. Then just drag the gesture recognizer onto the view controller in Storyboard, and it'll attach to the UIViewController's Content View instead of the UITableView.
Though at the end of the day, this is inherently a flawed approach, since swiping to flip pages in an app is only ever viable if you don't have any elements on the pages that also have swipe gestures in them. If you do, even if you code a workaround to make the gesture recognizer for the element in the view controller (in this case, a table view cell) fire instead of the page flipping swipe gesture, that creates an inconsistent user experience.
My suggestion: don't use a table view for such a form altogether. On top of the aforementioned mechanical UX issue, from a user perception perspective, there's nothing indicating visually that this is a table view and not just a scroll view, so there's nothing indicating to the user that swipe actions (Delete) are available. Use a scroll view instead, and take a different approach to deleting (Delete buttons that are always visible, Delete buttons that are only visible after the user hits Edit somewhere, etc.).

Related

unwinding segue, need to refresh tableview

I have looked all over for this problem and I cannot find an answer.
So on the first page of my app I have a page in a navigation controller. Within that page is a tableview. Within the cells of the table, there is a button. For the view controller of the cells, I say remove the button from superview if user is not signed in. So when you first load the app, there is no button.
Now if you click the sign in button (a button at the top of the page), it goes to that page, then there's two possible things that can happen. At first what I was doing was making a segue back to the main page. Everything worked perfectly fine. The button appears in the cells.
But I don't like how a second copy of the main page is being added to the stack of navigation controllers. So what I have explored with now is the popnavigationcontroller method and the unwind segue. So they both work but the problem is when it unwinds back to the new page, the button I mentioned earlier does not appear in the cells, even though its supposed to appear since the user is signed in. The reason for this is because the method "dequeueReusuableCell" is using the old cells, in which I have removed the button. And now that the button is removed, there is no easy way for me to add it back in at the right place in the view.
So what is the best solution here? At first I was looking for a way to "clear" all the reusuablecells for a tableView but I'm not sure if I found an answer. What I would like to do is when I rewind back to that navigation controller, refresh everything like it was the first time ever seeing it.
I guess another solution I could do is to perform a normal segue from the sign in page to the main page, and then remove the previous redundant main navigation controller. Is there a better solution?
When your controller pops off the stack, the underlying view controller will have its viewDidAppear(animated:) function called. So you could have:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.reloadData()
}
This is assuming based on your post that the issue is only about reloading your table. If you reload the table and your cells are still not updating properly, you have an issue with your dataSource not configuring the cells properly. But I cannot tell if this is the case without any code.
Edit: this was a cell reuse issue. Cell configuation had some code to remove a subview in some instances, but never add the subview back if it was supposed to be there. The simplest fix is to use isHidden instead of outright removing the subview.

Drag & Drop in MAster-DetailView Controller in iOS

I want to drag from the masterview tableview Cell to DetailView.
I try with touchesBegan & touchesEnded method but not working.
Can you please help me for this?
Thank you
This is actually not easy. You can start by
Adding a pan gesture recognizer (UIPanGestureRecognizer) to the root view controller's view (UIWindow.keyWindow!.rootViewController!.view).
When the pan starts (i.e. user touches the screen), loop through the master view's table view's visible cells to see if the point is inside any cell by using UIView's convertPoint:fromView:. You may need to adjust timing to avoid interfering with table view's scrolling and tapping.
If a cell contains the pan's point, create an "indicator view" (that shows that user is dragging) and add it to the root view controller's view, on top of everything else and position it properly, e.g. under user's finger.
When the pan changes (i.e. user moves his finger), update the indicator view's location.
When the pan ends (i.e. user releases his finger), check if the point is inside the detail view and do whatever you need to do.
Check this out. It demonstrates how to do drag drop within a view. Your problem is more complicated as it involves different view controllers, hence the touch handling must be done at a level higher than both master and detail view controllers.
Why are you using touchesBegan & touchesEnded methods? If you have the tableView you should use didSelectRowAtIndexPath delegate method. And you can also use segues if you are using storyboards.

How to make a switch from one view to the same view?

I'm creating a questionnaire app for iOS in Swift.
I only need one view for all questions. How do I make one generic view and make it look like I'm switching to the new view with swipe when only replacing some of the data on that view?
Alright, so I think I know what you're attempting to do. You could possibly do it like this. This is assuming you have a custom UIViewController subclass with all your textfields and labels on it; I've named this QuestionaireViewController.
let nextVC = QuestionaireViewController()
self.navigationController?.pushViewController(nextVC, animated: true)
Additionally, you'll want to set up unwind segues each time you create a new VC, so that if needed the Navigation Controller can segue back.
You can add an animation to your subviews (UILabels, etc.) on screen. You can add a separate animation to each swipe gesture and have the animation move in the direction of the swipe. I like this because you have some flexibility in what you animate and how you do so.
You'll need to setup swipe gesture recognizers and methods for each to handle the swipe and animate the layers.
If you want a "traditional feeling" swipe left / swipe right type of setup you'll need to setup a push animation with a subtype for each direction.

Resign first responder after touch on contentview

Here's my setup:
I have a view containing a small view at the bottom of the screen, which contains a text field. I have added some logic to move the whole view (including the small one) up as soon as the textbox is selected, and down as soon as the textbox disappears.
I have also added a gesturerecognizer to the whole thing, to resign first responder once the user taps somewhere else.
Afterwards, I added a ContentView to all of this, which in turn references a tableviewcontroller. It looks fine: a tableview in the back, the text field in its view at the bottom, once I tap the textfield everything is moved up and down as intended.
However, the gesturerecognizer doesnt work properly. It detects touches to the small view containing the textfield, but not on the tableview.
I have tried adding the gesturerecognizer to the tableview, but it didnt seem to make a difference - the gestures weren't recognized. I also tried adding another view on top of the ContentView - it worked, but it didn't pass the events to the tableview below.
I have created the views with storyboard and added the code to move the views programatically.
The gesture recognizer is working properly, make sure that it doesn't conflict with other event handlers. You can put break point into the method which is handling events to make sure it does really handles those events you wish.
As the alternative, put a blank view in front of table view and attach gesture recognizer. :)
I solved it using the answer provided [here]. I was not able to solve it with the storyboard gesture recognizer without additional code.1

Swipe-to-Delete on rightest UITableViewController inside UIPageViewController

Looks like UIPageViewController prevent UITableView to get touch events. My table view is placed in rightest page, so there is no potential problem to recognize gesture.
Is there any solutions of this problem?
Put this in your UIPageViewController's viewDidLoad function.
if let myView = view?.subviews.first as? UIScrollView {
myView.canCancelContentTouches = false
}
You can use this third party library which will allow the swipe gesture of the menu to have president over the uipageviewcontroller swipe
https://github.com/WinterKirk/MKSlidingTableViewCell
the important thing is that your whole view shouldnt only have these kind of cells cause then the uipageviewcontroller wont be able to swipe
but it works great in situations where you lets say have an image and comments under it and people should be able to delete the comments but swipe to the next pic on all other cells

Resources