ios YTPlayerView does not respond to touch - ios

I have a problem with YTPlayerView, I created a collection view, and in each cell is added subview YTPlayerView, the problem is that it shows great, but does not respond to pressing on view etc.
Not working on thumbnail page, when video playing all's fine.
How it's looking.
#pragma mark UICollectionView
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataSource.count;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
YTCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.identifierDataSource[indexPath.row]
forIndexPath:indexPath];
if (!cell) {
cell = [YTCollectionViewCell new];
}
if (!cell.loaded) {
[cell.playerView loadWithVideoId:self.dataSource[indexPath.row]];
cell.loaded = YES;
}
return cell;}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);
}
-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
YTCollectionViewCell* ycell = (YTCollectionViewCell*)cell;
[ycell.playerView stopVideo];}
-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
YTCollectionViewCell* ycell = (YTCollectionViewCell*)cell;
if (!ycell.loaded) {
[ycell.playerView loadWithVideoId:self.dataSource[indexPath.row]];
ycell.loaded = YES;
}else{
//[ycell.playerView playVideo];
}
}
`

Related

UICollectionView Assertion failure in createPreparedCellForItemAtIndexPath

my code is simple,just want to create a flow layout UIColloctionView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 7;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [UICollectionViewCell new];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(SCREEN_WIDTH / 2 - 5, 160);
}
and this is the error
*** Assertion failure in -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.9.1/UICollectionView.m:2115
Try using dequeue reusability of the collection view cell:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell * cell=[collectionView dequeueReusableCellWithReuseIdentifier:#"cell" forIndexPath:indexPath];
return cell;
}
as the documentation said
the collection view requires that you always dequeue views, rather than create them explicitly in your code
this is different from UITableView , just deque the cell all the time
wrong:
UICollectionViewCell *cell = [UICollectionViewCell new];
return cell;

Odd blank space at the top of horizontal UICollectionView

I have a blank space that I can't locate the cause of at the top of a UICollectionView.
I have disabled the header in the storyboard so I don't believe it to be that.
Here is a picture:
The code for the CollectionView
- (void)setupCollectionView
{
[self.scoreCollectionView setDataSource:self];
[self.scoreCollectionView setDelegate:self];
[self.scoreCollectionView registerClass:[AAScoreCell class] forCellWithReuseIdentifier:cellIndentifier];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
AAScoreCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifier forIndexPath:indexPath];
if (_selectedIndexPath) {
[cell showSelection:[indexPath isEqual:_selectedIndexPath]];
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
AAScoreCell *cell = (AAScoreCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell showSelection:![indexPath isEqual:_selectedIndexPath]];
_selectedIndexPath = [indexPath isEqual:_selectedIndexPath] ? nil : indexPath;
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
AAScoreCell *cell = (AAScoreCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell showSelection:NO];
_selectedIndexPath = nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.scoreCollectionView.frame.size.height-50, self.scoreCollectionView.frame.size.height-50);
}
Not going to pretend I understand why but:
[self setAutomaticallyAdjustsScrollViewInsets:NO];
solved the issue for me

How to add Load more cell in UICollectionView?

I want to add load more cell in UICollectionview ? can anyone tell me how can i add load button ? i have created collectionview that works fine but i want to add Load more button in bottom of collection view cell like this
Here's my collection view
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
switch (section) {
case 0: return 66;
case 1: return 123;
}
return 31;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSUInteger count = [self.stockImages count];
if (row == count) {
//Add load more cell
}
DemoCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[DemoCellView reuseIdentifier] forIndexPath:indexPath];
// Configure the cell
cell.titleLabel.text = [NSString stringWithFormat:#"%ld", (long)indexPath.item + 1];
NSLog(#"%#", self.stockImages[indexPath.item % self.stockImages.count]);
cell.imageView.image = self.stockImages[indexPath.item % self.stockImages.count];
return cell;
}
#pragma mark <DemoLayoutDelegate>
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// Do something
// Insert new cell after clicking load more data
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout *)collectionViewLayout heightForHeaderInSection:(NSInteger)section {
return kFMHeaderFooterHeight;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForFooterInSection:(NSInteger)section {
return kFMHeaderFooterHeight;
}
You can Add a footer
- (UICollectionReusableView *)collectionView:(JSQMessagesCollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
{
if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
//load your footer you have registered earlier for load more
[super dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:#“load more footer”
forIndexPath:indexPath];
}
return nil;
}
In your cellForItemAtIndexPath method you can check this:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ImageCollectionViewCell *cellImage;
AddMoreCollectionViewCell *addMoreCell;
if(indexPath.row < [_dataSource numberOfItems]){
cellImage = [collectionView dequeueReusableCellWithReuseIdentifier:ImageCollectionCellIdentifier
forIndexPath:indexPath];
[cellImage configureForMediaViewModel:[_dataSource mediaViewModelForItemIndex:indexPath.row] delegate:self];
return cellImage;
}else{
addMoreCell = [collectionView dequeueReusableCellWithReuseIdentifier:AddMoreCollectionCellIdentifier
forIndexPath:indexPath];
addMoreCell.delegate = self;
return addMoreCell;
}
}
where ImageCollectionViewCell is the main kind of cells and AddMoreCollectionViewCell is a cell with a plus ('+') symbol and other stuff.
With this method, AddMoreCollectionViewCell always add at end of your collection view.
Hope it helps!

[UICollectionView performSelector:withObject:]: message sent to deallocated instance

I am having problem with my iOS app which I am not sure what is the root cause of it even after I've turned on NSZombie to debug.
Already tried to google with reliable source but still couldn't get any answer.
For my iOS App, I am using MMDrawerController Library as the left slide menu. Which I am having a problem when I switching view from left menu, if the page contains UICollectionView, it will crash with the message below.
[UICollectionView performSelector:withObject:]: message sent to deallocated instance
The view load smooth for the first time, but when I attempt to switch back from another view, it crashed with the error above.
Here are my UICollectionView Data Source and cell builder functions
#pragma mark: UICollectionViewCell Builder
- (ItemNormalCVCell *)buildItemNormalCVCell:(NSIndexPath *)indexPath
{
ItemNormalCVCell *cell = [self.mCollectionView dequeueReusableCellWithReuseIdentifier:#"CVCellItemNormal" forIndexPath:indexPath];
return cell;
}
- (LoadingCVCell *)buildLoadingCVCell:(NSIndexPath *)indexPath
{
LoadingCVCell *cell = [self.mCollectionView dequeueReusableCellWithReuseIdentifier:#"CVCellLoading" forIndexPath:indexPath];
return cell;
}
#pragma mark: UICollectionView DataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSInteger itemsCount = self.items.count;
if( self.isLoading_.boolValue )
return itemsCount + 1;
return itemsCount;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger itemsCount = self.items.count;
if( self.isLoading_.boolValue ){
if( indexPath.row == itemsCount )
return [self buildLoadingCVCell:indexPath];
}
return [self buildItemNormalCVCell:indexPath];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cvWidth = (self.view.frame.size.width / 2) - 1.f;
return CGSizeMake(cvWidth, 300.f);
}
- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 1.f); // top, left, bottom, right
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 1.f;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 1.f;
}

iOS: Scroll one cell at a time

I have horizontal scrolling set up now I would like for it to sort of scroll/snap one cell at a time when scrolling side to side.
Could someone shed some light? Here's the code I have so far:
- (void)viewDidLoad
{
[super viewDidLoad];
}
#pragma mark - UICollectionView Datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:#"MyCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(50, 20, 50, 20);
}
[collectionView setPagingEnabled:YES]; might do the trick?
http://adoptioncurve.net/archives/2013/04/creating-a-paged-photo-gallery-with-a-uicollectionview/

Resources