Я использую представление коллекции внутри моей ячейки tableview.
Для этого я создал класс ячеек tableview и внутри него определил collectionview. У меня есть 2 раздела для collectionview, и у меня прямо сейчас возникает проблема с настройкой indexpath, поскольку мне требовалось, чтобы indexpath проверял, какой индекс коллекции щелкнул.
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(FifaPlanTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setCollectionViewDataSourceDelegate:self indexPath:indexPath];
}
interface FifaPlanCollectionView : UICollectionView
@property (nonatomic, strong) NSIndexPath *indexpath;
@end
@interface FifaPlanTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet FifaPlanCollectionView *collectionViewFifa;
- (void)setCollectionViewDataSourceDelegate:(id<UICollectionViewDataSource, UICollectionViewDelegate>)dataSourceDelegate indexPath:(NSIndexPath *)indexPath;
- (void)setCollectionViewDataSourceDelegate:(id<UICollectionViewDataSource, UICollectionViewDelegate>)dataSourceDelegate indexPath:(NSIndexPath *)indexPath
{
self.collectionViewFifa.delegate = dataSourceDelegate;
self.collectionViewFifa.dataSource = dataSourceDelegate;
self.collectionViewFifa.indexpath = indexPath;
[self.collectionViewFifa reloadData];
}
На этом этапе self.collectionViewFifa.indexpath = indexPath; приложение вылетает и говорит:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionView setIndexpath:]: unrecognized selector sent to instance 0x7fa7aa016000'
Может ли кто-нибудь сообщить мне, что я здесь делаю не так?
да, я установил класс в FifaPlanCollectionView в раскадровке
@SyedFarazHaiderZaidi Попробуйте изменить имя переменной indexPath в FifaPlanCollectionView.
Я также меняю его на другое имя, но оно все еще не работает
@SyedFarazHaiderZaidi Просто удалите метод [self.collectionViewFifa reloadData], угадайте, что его перезагрузка бесконечна.
@SyedFarazHaiderZaidi Все ячейки в tableView - это FifaPlanTableViewCell. Это правильно?





Вы можете попробовать использовать cellForRowAtIndexPath вместо willDisplayCell,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FifaPlanTableViewCell *cell = (FifaPlanTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
[cell setCollectionViewDataSourceDelegate:self indexPath:indexPath];
}
Предположим, событие щелчка из ячейки
[cell.buttonInstance addTarget: самостоятельное действие: @selector (getIndexActionMethod: событие :) forControlEvents: UIControlEventTouchUpInside];
- (void) getIndexActionMethod: (UIButton *) событие отправителя: (UIEvent *) события {
UITouch * touch = [[события allTouches] anyObject];
CGPoint touchPos = [touch locationInView:self.tableViewInstance];
NSIndexPath *indexPath = [self.tableViewInstance indexPathForRowAtPoint:touchPos];
}
Вы установили имя класса для представления коллекции в xib или раскадровке?