<分区>
<分区>
我都经历过
How to get the selected CollectionViewCell in the UICollectionView?
how to access from UICollectionViewCell the indexPath of the Cell in UICollectionView
但是我的问题与上面两个有点不同。
我的 mybookingsCell 上有来自 nextByCollectionView 的审核按钮
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
DetailObject * Obj=[[DetailObject alloc]init];
Obj=[self.listOfObjects objectAtIndex:indexPath.row];
// DetailObject is NSObject class and listOfObjects getting values from API
// mybookingsCell.headerLabel.text=Obj.name; like this i am putting the values in cell
NearbyCell *mybookingsCell = (NearbyCell *)[cv dequeueReusableCellWithReuseIdentifier:@"nearby" forIndexPath:indexPath];
[mybookingsCell.reviewBtn addTarget:self action:@selector(didTapReviewBtn:) forControlEvents:UIControlEventTouchDown];
}
-(IBAction)didTapReviewBtn:(id)sender
{
}
单击“查看”按钮后,我需要单元格上的详细信息。 我尝试过这样的
-(IBAction)didTapReviewBtn:(id)sender
{
NearbyCell *clickedCell = (NearbyCell *)[[sender superview] superview];
NSIndexPath *clickedButtonIndexPath = [self.nearByCollectionView indexPathForCell:clickedCell];
}
但是我的应用程序崩溃了。所以帮助我如何通过相应的点击按钮获取单元格详细信息。
最佳答案
我已经修改了你的代码
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
DetailObject * Obj=[[DetailObject alloc]init];
Obj=[self.listOfObjects objectAtIndex:indexPath.row];
// DetailObject is NSObject class and listOfObjects getting values from API
// mybookingsCell.headerLabel.text=Obj.name; like this i am putting the values in cell
NearbyCell *mybookingsCell = (NearbyCell *)[cv dequeueReusableCellWithReuseIdentifier:@"nearby" forIndexPath:indexPath];
[mybookingsCell.reviewBtn addTarget:self action:@selector(didTapReviewBtn:) forControlEvents:UIControlEventTouchDown];
mybookingsCell.reviewBtn.tag = indexPath.row;
}
-(IBAction)didTapReviewBtn:(id)sender
{
NearbyCell *clickedCell = (NearbyCell *)[[sender superview] superview];
int *clickedButtonIndexPathRow = (UIButton*)sender.tag;
// Using this you can get data from your data source arrray.
}
关于ios - 如何在单击按钮时获取 CollectionViewCell 详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31671096/