is it possilbe to uiview, detect from pop navigation controller? - ios

I have a collectionview called "A" inside another collectionView cell,
in collectionView "A"'s cell, there is uiView.
In this uiview I play some animation.
When I click collectionView "A"'s cell, It pushes navigation controller, and I stop the animation.
I want to play animation again when I pop navigation controller.
Is it possibe to uiview, detect when view is appear again?
I know uiviewcontroller has viewdidload or viewwillapper to detect, but i need uiview to know.

You'll have to keep a weak reference of that cell and you can access the specific view when you pop the view controller.
Save the index you clicked and get that specific cell using this line and play the animation collectionView.cellForItem(at: IndexPath)

Related

How can I get a Table View to register taps when each cell has an Image View covering it?

I've been trying to create table view cells each with a UIImageView serving as a background for them. However, when I tap on each cell the table view will not register the click and will not transition to the view controller I have hooked up, even while I'm using the didSelectRowAtIndexPath function.
I realize it's probably an issue with the ImageView obstructing the table views ability to register the cell tap. The cells will transition however when I drag my finger/mouse on it from left to right, just not on taps. I tried to use a Tap Gesture Recognizer on the Image View however it only worked for the cell at the very top and not all of them. How do I tackle this issue?
Here is an image of the table view cells so you have an idea of what I'm working with: http://imgur.com/a/Ku4uD. Thank you!
If you uncheck User Interaction Enabled on your Image View, the problem should be solved. When running into a problem always check the user interaction of the most child view and work your way up.
One trick I have also learned is to create a subclass of a child and override touchesShouldCancel like so:
override func touchesShouldCancel(in view: UIView) -> Bool {
print("touchesShouldCancel")
//Run extra code that you want when the user selects this view
//then still retrieve the tap by its parent.
return false
}
I am unsure of exactly what your problem is, but I would delete whatever segue that you have, add a new one by dragging from the yellow circle on the left side of the center portion of the top of your tableView ViewController inside the storyboard, to the viewController that you desire it to segue to. Give the segue an appropriate identifier, and then inside your tableView class under tableView didSelectRow add performSegue(withIdentifier: "ChosenIdentifier", sender: indexPath)
Then in prepare forSegue add in:
if let vc = sender.destination as? TheViewControllerYouAreSegueingTo {
if let indexPath = sender as? IndexPath {
vc.variableIdentifyingWhatCellWasClicked = indexPath.row
}
}
with whatever adjustment is needed to meet your specific needs.

I want to pass touch event for a transparent custom cell to its parent view (which is a pageview controller)?

I'm trying for this solution from many days, I have a scenario where I want to pass touch even (Swiping for page view controller) of my first custom cell to the parent view which is a page view controller.
Here my first cell in the table view is a transparent cell. It is not visible instead of we can see the background view which is a super class of table view controller and it is a page view controller. So here I want to pass the touch event which should be swiping for page view controller. And all the remaining cells are not transparent. Here I'm sending the image so that you can understand. easily. So help me out in passing the swipe/touch to my page view controller Basic Look with transparent cell on top So in that transparent cell area we can see the super view of table view controller which is a page view controller.
As you can see left side is the basic look, and in that you can see the page view controller, and then the right side image is when we scroll the cells it will look like this.
So now you can understand clearly the height of table view and my requirement too.
So how to pass touch/ swipe event to the page view controller when we select transparent cell(indexpath.row ==0 first cell)
I tried the solution that given but no use..
You can add one more view on top of it (pageview -> cellview -> new view on top with opacity = 0). Next add swipe gesture to new view and finally make a newView.delegate = pageviewController to capture swipe event.
#protocol NewViewControllerDelegate<NSObject>
-(void)gestureDidFire;
#end
#interface NewViewController : UIViewController
// you gesture outlet look like IBAction *swipeGestureReconizer;
#property (nonatomic, assign)id <NewViewControllerDelegate>delegate;
#end
//newViewContrlloer.m
- IBAction swipeGestureReconizer
{
if(self.delegate && [self.delegate responseToSelector:#seletor(gestureDidFire)])
{
[self.delegate gestureDidFire];
}
}
//in your page view interface
#interface yourPageView()<NewViewControllerDelegate>
{
//need instance of newView
newViewController.delegate = self;
}
-(void)gestureDidFire
{
//implement what you want
}

Tapping UIButton doesn't call its action although visually it receives the event

I have a view in a xib file that contains a button and other 2 views and they don't overlap. The view file's owner is a custom class derived from UIViewController. The custom view controller is created programmatically by this code:
let sfvc = SelezioneFascicoloViewController(nibName: "SelezioneFascicoloView", bundle: nil)
viewObject.addSubview(sfvc.view)
sfvc.updateWithAttributes(attrs, inFascicolo: self.fascicolo!)
viewObject is a view contained in a custom UICollectionViewCell.
The button has a handler connected to the touchDown event (but any other event produce the same problem) and it is defined in the custom UIViewController (SelezioneFascicoloViewController)
I have flagged showsTouchOnHighlight for the button just to see if it receive the event.
Well, the view shows up correctly, if I tap the button I can see the glow but the handler isn't called.
All the views in the hierarchy have the UserInteractionEnabled set to true, and their sizes are correct so the button isn't outside the superview frame.
Also I have a UITapGestureRecognizer in the UICollectionViewController derived class that contains the UICollectionViewCell, and its handler is fired if I tap outside the button, but not when I tap inside the button, and this is as it should be.
Can someone give me some advice for this kind of problem?
Edit: added a screenshot
Interface Builder screen shot
Thank beyowulf.
Everything works if I add SelezioneFascicoloViewController as a child view controller, in this way:
let sfvc = SelezioneFascicoloViewController(nibName: "SelezioneFascicoloView", bundle: nil)
self.addChildViewController(sfvc)
viewObject.addSubview(sfvc.view)
sfvc.didMoveToParentViewController(self)
sfvc.updateWithAttributes(attrs, inFascicolo: self.fascicolo!)

Passing a Custom Cells image views image to a new view controller

I have a view controller which has a UITableView with some custom cells.
Within the custom cells I have a main UIImageView. I add a tap gesture recogniser to the image view, so that when the image is tapped the handleImageTap method is called.
Question
What I am trying to do is pass the image from the selected UIImageView (from the specific cell) into a new View Controller.
When the handleImageTap is called I run the following:
UIImageView *imageView = (UIImageView *)gestureRecognizer.view;
// send the image instead of self when firing the segue
[self performSegueWithIdentifier:#"remindMeTurnInfo" sender:imageView];
I then have the following in the prepareForSegue method:
if ([segue.identifier isEqualToString:#"remindMeTurnInfo"]) {
UIImageView *imgView = (UIImageView *)sender;
MESPlayedTurnReminderViewController *VC = segue.destinationViewController;
VC.mainImageView.image = imgView.image;
}
The above does not work the image is not passed across. How can I get the image from the selected cells image view to the new controller?
Also
Sometimes when the image view of the cell is selected the didSelectRowAtIndexPath method is called. This is not correct and should not be called when the image view is tapped. This doesn't appear to be all the time, is there anyway to ensure this is not called?
I also need a reference to the cell that the imageview is within for the prepareForSegue method. How do I get the reference for the cell that the imageview is within, when the cell is (should not be) actually selected here.
Your question has 2 problems.
First, you should not use table view cells to store data. Table view cells are view objects. They display data. When the user triggers an action on a cell, you should figure out the indexPath of the cell, use that info to look up the data in your model (the image for the selected row or section/row, in your case) and use that.
Second, you should never try to manipulate another view controller's views. Treat the other VC's views as private. This is a biggie. Reaching into another VC and touching its views violates the encapsulation of the two VCs and means that the VC doing the touching becomes dependent on the appearance of the "touched" VC. Bad. Then you can't change the appearance of the touched VC without breaking other code. It also doesn't work right after creating the new VC, because it's views don't exist yet.
Instead, you should add an "imageToUse" property to the other view controller, and set THAT in the prepareForSegue method. Then the second view controller can take the image and install it in it's image view in it's viewWillAppear method.
I changed the approach.
Putting a UIImage on the destination Controller instead. Then in the viewDidLoad of this controller I pass the image into the UIImageView. I imagine this is because the image view is not created yet.

Static Table View cell seque to ViewController clicking in Cell

When I create a table view with static cells, and connect cell with other ViewController in storyboard and run this, It is seque when clicked in disclosure indicator, but when click in cell it`s nothink. How can I seque it with click on the cell?
Control drag your cell to the other view controller and click the first modal. Not the one under accessory action.

Resources