I have set a UICollectionView to 'Paging Enabled'. I want to be informed when a UICollectionViewCell becomes active.
It seems like the collectionView:didSelectItemAtIndexPath: of the UICollectionViewController cannot achieve this effect: It only fires when a user explicitly select a cell, not when the cell is swiped to the front.
Each cell has a view controller associated with it. I probably can use viewDidLoad to as a proxy of this event. But it does not sound like a clean solution.
You can use collectionView:didEndDisplayingCell:forItemAtIndexPath: to detect that something changed and visibleCells to know what now on screen
Related
I have a UICollectionView which allows for a user to select a cell and upon doing so view 'A' will appear. I am wondering if it is possible for the subviews of this cell, ex: UIlabel and UIImageView to provide a different functionality for when they alone are selected. For example, if the UIImageView is selected, I want to segue to view 'B' as opposed to 'A'.
I have attempted to implement a UITapGestureRecognizer for both the label and the image, however, the cell's functionality overrules and the resulting view is still 'A'. Any ideas?
Thank you in advance.
What you want to achieve is possible through delegates if you don't have custom cell make a custom cell class then inside custom cell declare your protocol
I assume you have to disable the default behavior of the collection view cells:
cell.selectionStyle = UITableViewCellSelectionStyle.none
However, if you set that and you encounter an overlap issue, please take a look at the 'cancelTouchesInView' property of the 'UITapGestureRecognizer'. Basically, by setting that to false, you allow the children to also receive touch actions.
Furthermore, do not forget each gesture recognizer should have it's own method for you to be able to segue into two different places.
I have a two-days-brain-breaking-question to all of you:
I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:
Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.
Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.
I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...
Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.
you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.
Send and receive messages through NSNotificationCenter in Objective-C?
Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.
At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.
Than all your cells may receive notification and react to it.
This is not an optimal way of receiving callbacks, but maybe the simplest.
I need to implement UITableViewCell what will move itself to right when user tap on it and then slide its finger to right. I need also to track a distance what cell has been moved. Is there any way to do something like this?
You need to use a scrollview. Implementing the delegate of that scrollview (in the cell itself or the view controller), you will know exactly how much the user has scrolled.
Here is an open source control which implements a similar functionality:
https://github.com/CEWendel/SWTableViewCell
Perhaps it will be of assistance to you.
I have a Static TableViewCells on a storyboard. There are just labels in those cells. I would like to fire IBAction event upon touch. What I am doing right now is create a full-size white button and linked to IBAction. But it doesn't show highlighted color when the cell is selected because cell is behind the button.
UITableViewCells have a delegate method specifically for handling row touches -tableView:didSelectRowAtIndexPath:
If you need a custom button over each cell, subclass UITableViewCell instead of going through a storyboard. As much as they may be a timesaver, storyboards are really a limiting factor when it comes to nitty gritty iOS programming.
Try adding this in your cellForRowAtIndexPath (when you initialize each cell):
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
Does this fix it?
I'm stuck with the problem that I want to know in my UITableView if a specific UITableViewCell, let's say the first, is still visible or already off the visible area.
I would also be ok to know if the cell of interest is now beeing reused at an other indexPath of the table.
One of my - later and frustrated approaches - was to have a thread that knows the first cell object and frequently pings it to check if a value I did set in the cell changed. Obviously a not so good solution.
Andy ideas how to do this right?
Remember that UITableView is UIScrollView subclass and its delegate also confirms to UIScrollViewDelegate protocol as well.
So in your table delegate you can implement scrollViewDidScroll: method and check contentOffset - if it's more then first cell height then first cell is not visible. You can also get the array off all currently visible cells using -visibleCells method, but I think knowing contentOffset should be enough.