Multiple items being selected at once
Closed this issue · 5 comments
Hi,
I'm having an issue where after selecting an item, every sixth item is also being selected. Five cells are being presented at a time. It appears my everything is set up properly, I only have one section and one row so I set the tableview up as such. In tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) I create an instance of ASOXScrollTableViewCell with the identifier for a prototype tableview cell and return the cell. In horizontalScrollContentsView cellForItemAtContentIndexPath I instantiate an instance of my custom subclass of UICollectionViewCell. In horizontalScrollContentsView didSelectItemAtContentIndexPath I instantiate the cell as such:
var cell: XScrollViewCell = horizontalScrollContentsView.cellForItemAtIndexPath(contentIndexPath) as XScrollViewCell
and set the background color to green. After selecting a cell, the correct cell is selected, but still every sixth cell is also being presented with the green background. Could this be an issue with reusing the cells as it appears as every 6th cell dequeued. I've been trying to solve the issue with no luck thus far.
Thanks,
Kurt
Hi,
Alternatively you can customise the selected backgroundView in the setSelected method of your custom UICollectionViewCell
-
(void)setSelected:(BOOL)selected {
[super setSelected:selected];UIView *backView = [[UIView alloc] initWithFrame:self.frame];
backView.backgroundColor = [UIColor greenColor];
self.selectedBackgroundView = backView;
}
And you do not need to add any action in the delegate method of
- (void)horizontalScrollContentsView:(UICollectionView *)horizontalScrollContentsView didSelectItemAtContentIndexPath:(NSIndexPath *)contentIndexPath inTableViewIndexPath:(NSIndexPath *)tableViewIndexPath;
Let me know if I do not understand you correctly. You can also send me some of your setup codes so I can have better understanding.
You can also check this in the XScroll project sample.
Hi,
Thank you for the quick response! The problem with setSelected is that I am
using Swift and it appears that setSelected is not a function for
UICollectionViewCell and therefor cannot be called. I did try using a
objective-c file so I could call this method, but that still didn't work. I
think it may have something to do with the fact that it is reusing the cell?
I've attached files of my view controller and cell if you'd be willing to
take a look. They aren't very long so they should be easy to dissect. Thank
you very much for your help!
Cheers,
Kurt
On Thu, Dec 4, 2014 at 7:16 PM, Agus Soedibjo notifications@github.com
wrote:
Hi,
Alternatively you can customise the selected backgroundView in the
setSelected method of your custom UICollectionViewCell
(void)setSelected:(BOOL)selected {
[super setSelected:selected];UIView *backView = [[UIView alloc] initWithFrame:self.frame];
backView.backgroundColor = [UIColor greenColor];
self.selectedBackgroundView = backView;
}And you do not need to add any action in the delegate method of
- (void)horizontalScrollContentsView:(UICollectionView
*)horizontalScrollContentsView didSelectItemAtContentIndexPath:(NSIndexPath
*)contentIndexPath inTableViewIndexPath:(NSIndexPath *)tableViewIndexPath;Let me know if I do not understand you correctly. You can also send me
some of your setup codes so I can have better understanding.You can also check this in the XScroll project sample.
—
Reply to this email directly or view it on GitHub
#6 (comment)
.
Sorry mate, I could not find your attached source codes.
Hi,
sorry must not have attached sending straight to github. Anyway I managed
to fix the issue. I just had to implement
horizontalScrollContentsView.indexPathsForSelectedItems() in
cellForItemAtContentIndexPath
in order to get the list of selected indexPaths. For the indexPaths which
were selected, I just set the respective background.
Thanks for your help!
Best,
Kurt
On Fri, Dec 5, 2014 at 2:45 AM, Agus Soedibjo notifications@github.com
wrote:
Sorry mate, I could not find your attached source codes.
—
Reply to this email directly or view it on GitHub
#6 (comment)
.
Great, you did it :)