Ios tableview单元格内的Collectionview索引问题
我在我的Ios tableview单元格内的Collectionview索引问题,ios,objective-c,uitableview,uicollectionviewcell,Ios,Objective C,Uitableview,Uicollectionviewcell,我在我的tableview单元格中使用集合视图 为此,我创建了一个tableviewcell类,并在其中定义collectionview。我有2秒钟的时间来查看collectionview,我现在就要解决设置indepath的问题,因为我需要indepath来检查单击了哪个集合索引 #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView willDisplayCell:(FifaP
tableview
单元格中使用集合视图
为此,我创建了一个tableview
cell类,并在其中定义collectionview
。我有2秒钟的时间来查看collectionview
,我现在就要解决设置indepath
的问题,因为我需要indepath
来检查单击了哪个集合索引
#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];
}
有人能告诉我我做错了什么吗?您可以尝试使用
cellforrowatinexpath
而不是willDisplayCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FifaPlanTableViewCell *cell = (FifaPlanTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
[cell setCollectionViewDataSourceDelegate:self indexPath:indexPath];
}
假设单击单元格中的事件 [cell.buttonInstance addTarget:self action:@selector(getIndexActionMethod:event:)for ControlEvents:UIControlEventTouchUpInside] -(void)getIndexActionMethod:(UIButton*)发送方事件:(UIEvent*)事件 { UITouch*touch=[[events AllTouchs]anyObject]
CGPoint touchPos = [touch locationInView:self.tableViewInstance];
NSIndexPath *indexPath = [self.tableViewInstance indexPathForRowAtPoint:touchPos];
}您是否在xib或情节提要中为集合视图设置了类名?是的,我已在中将该类设置为FifaPlanCollectionViewstoryboard@SyedFarazHaiderZaidi尝试在FifaPlanCollectionView中更改indexPath的变量名。我也将其更改为其他名称,但仍然不是working@SyedFarazHaiderZaidi只需移除[self.collectionViewFifa reloadData]方法猜测其重新加载无限时间。
CGPoint touchPos = [touch locationInView:self.tableViewInstance];
NSIndexPath *indexPath = [self.tableViewInstance indexPathForRowAtPoint:touchPos];