Drag & Drop in MAster-DetailView Controller in iOS - 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.

Related

Swift canEditRowAtIndexPath not working in UIPageViewController EZSwipeViewController

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.).

peek and pop for specific image from tableview cell

I have a table that displays different images (usually between 1 and 4 per cell). The images are programmatically added and aligned via auto layout.
I'm trying to implement the force touch method peek and pop, so that a user can push down on any of the images and the peek and pop will work.
I tried several different things to get the specific image, but none seem to be working. I added a tap gesture recognizer to each of the images in the cell that sends the index of the picture to the tableviewcontroller via a delegate, but the force touch method was called before the tap gesture was. I also tried creating an nsinteger property for the cell that gets set each time any of the cells get the touched. But this also doesn't get called before the force touch method.
How should this be implemented?
Peek and pop is merely a way of previewing a view controller transition. So think about how you would implement a transition where you tap on the cell and present the image in a presented view controller. Now configure that transition in the storyboard. Now check the Peek & Pop checkbox!

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

ImageView not responding to touches

In XCode, I created a xib file with several image view, some stacked on others. The entire view has a single view controller that has a connection to every image view. I guess my first question is, are all the image views direct subviews of the entire view? Anyways, when ever the over all image view is touched, I detect it with touches began / touches moved. It works perfectly. However, there is one image view in particular that I want to know if it is being touched. How can I, from the master view's touches began / touches moved, find out if a sub view within it was touched? I want to do it this way because everything else I tried did not work. For the sub view, i created a view controller and set its view to the sub view in question. I set up the touches began / touches moved methods inside the controller, but they do not react to touches at all.
For UIImageView instances, you need to explicitly do setUserInterActionEnabled=YES

Using bringSubviewToFront in Ipad scrollview

In my Ipad app, I have a split view in which the detail view is a scroll view...
I have 3 subviews to the scrollview which are tableviews...
How do I use - (void)bringSubviewToFront:(UIView *)view to bring one of the subviews of the scrollview to the front when an action is performed? (since Views are "stacked" in the order they're added with the last one on top). Should I write the code in the subview or in the detailViewController and how do I call it?
You write the code in the controller.
The controller should have access to the table views through IBOutlet properties. Or, if you didn't set them up using a nib, the controller should have been the one to create them.
If a button tap, for example, is responsible for showing a particular table view, the button's action handler method is where you call the bringSubviewToFront: method.
HOWEVER: It sounds like you have three table views on top of each other and are using bringSubviewToFront: to show the current one, and they are all inside a UIScrollView.
Each UITableView contains a UIScrollView. Don't put a scrollview inside a scrollview, they will fight over tracking touches and things will get weird. Just put the three table views inside a plain UIView.
Instead of bringSubviewToFront:, you ought to consider hiding the inactive views (call setHidden:). That way, the hidden views won't be considered part of the responder chain (won't get sent events).

Resources