Така че имам UICollectionView и персонализирана клетка и всичко се показва и работи чудесно. Регистрирам класа във viewDidLoad:
myCollectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:layout];
[myCollectionView setDataSource:self];
[myCollectionView setDelegate:self];
[myCollectionView setBackgroundColor:[UIColor myColor]];
[myCollectionView registerClass:[SBCustomCell class] forCellWithReuseIdentifier:@"Cell"];
В моя метод cellForItemAtIndexPath премахвам клетката от опашката и задавам нейните свойства и я връщам:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
SBCustomCell *cell= [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell setName: "My Name"];
cell.image = [UIImage imageNamed:@"lol.png"];
cell.score = 100.0;
cell.backgroundColor=[UIColor whiteColor];
return cell;
}
Всичко това работи добре и се показва в потребителския интерфейс. Проблемът ми е, когато задам разпознавател на жестове в collectionView, когато натисна дълго определена клетка, искам да имам достъп до нейните свойства. Опитвам се да го направя като такъв:
-(void)handleLongPress:(UILongPressGestureRecognizer *)longPressRecognizer {
CGPoint locationPoint = [longPressRecognizer locationInView:myCollectionView];
if (longPressRecognizer.state == UIGestureRecognizerStateBegan) {
NSIndexPath *indexPathOfMovingCell = [myCollectionView indexPathForItemAtPoint:locationPoint];
SBCustomCell *cell= [myCollectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPathOfMovingCell];
NSLog(@"%@",cell.name);
Когато се опитам да осъществя достъп до някое от свойствата на персонализираната ми клетка, то е (null) в конзолата. Защо така? какво правя грешно