peek and pop for specific image from tableview cell - ios

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!

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

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 recognize gesture from custom view in VC

I have tableVC, it contains from cells with customViews.
That customViews contains from 3 imageViews, so then I click on imageView, it makes some action. To achieve it I added UITapGestureRecognizers to imageView.
Now I need to be notified then this cells are tapped in my tableVC. I get this events in didSelectRowAtIndexPath, but only if I do not touch any of imageViews with gestures.
How can I receive tap notification in my tableVC about touching my cell completely ?
If you want to get cell that is tapped - didSelectRowAtIndexPath is way to go. If you want to get the tapped image inside that cell - implement delegate for that ( https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html ) and do the corresponding actions. I see that you mentioned didSelectRowAtIndexPath, but I am not sure what was your problem.
Also I didn't put any code since I don't know if you are using swift or objective-c.

Modify or delete table view cell in master-detail ipad app

I am developing a simple master-detail ipad app. Using xcode template for master-detail app when "Edit" navigation item is pressed in table view cell red circle appears which allows to delete selected cell.
In my app I would like to have the following: when edit button is pressed each cell can be deleted or modified (by performing segue to detail view). In other words with the red circle I would like to have another "icon" to modify the contents of that cell. Is it possible to perform this and how can be it done?
You can do this kind of stuff in multiple ways.
First is that you assign a custom gesture like swipe on the cell using the UIGestureRecognizer with custom selector that will called each time when the cell is swiped.
You can then display the buttons that are initially hidden from User.
Look into the following post to understand it better - How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views
You could always instead of using the default Edit button, implement a swipe feature that allows the user to swipe the cell to view more options. This link provides a tutorial walkthrough on how to implement this functionality.
Also, this StackOverflow post might help as well if this is the direction you choose to take.

Push Detail View from UITableView only on a specific UIImage in the cell?

I've got a UITableView which pushes a detail view when I tap any of its cells. I'd like that segue to only occur when tapping a specific part of the cell, a UIImageView at its left side. Tapping the rest of the cell should trigger a UITapGestureRecognizer which triggers a different method.
How can I override the default tap on the UITableViewCell, so that simply tapping anywhere on the cell doesn't trigger the segue to the detail view? I still want that transition, just only triggered by the UIImageView.
I think you could achieve that by connecting the segue with the image in the prototype cell (Never tried that myself) and not with the table view.
If you don't have a prototype cell then you should programmatically invoke an IBAction type of method with the image views. Well, Image Views cannot do that. Simply abuse a UIButton of the same size, custom style and assign the image to that button. Works fine.
(It does not need to be an -(IBAction) type of method, but it does not harm and doing so ensures that everything works fine.)
Within that action method invoke the segue programmatically. The segue needs to have an ID for that which is unique within the storyboard.

Resources