gpt4 book ai didi

ios - 单击tableview Cell中的Collectionview时如何找到tableview的索引路径

转载 作者:行者123 更新时间:2023-11-28 19:31:18 27 4
gpt4 key购买 nike

我有一个包含 Collection View 的 tableview 单元格。

CollectionView 包含来自服务器的图像。

我想要用户点击过的特定图像。IE。让 Tableview 有 4 行。在四行中,我在每个 tableview 行中都有集合。当我点击第 3 行 collectionview 单元格时,我必须从该行获取该图像。

代码在这里

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell = (ISclassifiedCell*)[_isclassifed_tblview dequeueReusableCellWithIdentifier:@"ISclassifiedCell" forIndexPath:indexPath];
[cell.layer setCornerRadius:4.0f];
[cell.layer setMasksToBounds:YES];
cell.profile_img.layer.cornerRadius=4.0f;
cell.profile_img.layer.masksToBounds = YES;
cell.iseventtype_lbl.text=[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"title"];
cell.eventtype_lbl.text=[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"category"];
cell.description_lbl.text=[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"description"];

UIFont *font=[UIFont fontWithName:@"Montserrat" size:14.0];

CGFloat size = [self getLabelHeightForString:cell.description_lbl.text font:font];
cell.description_lbl.frame=CGRectMake(cell.description_lbl.frame.origin.x, cell.description_lbl.frame.origin.y, cell.description_lbl.frame.size.width, size);
NSString *clubberid=[NSString stringWithFormat:@"%@",[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"clubberId"]];
cell.clubbername_lbl.text=[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"clubberName"];

if ([clubberid isEqualToString:[NSString stringWithFormat:@"%@",mainclubberId]]) {

[cell.editbutnoutlet setImage:[UIImage imageNamed:@"note-interface-symbol"] forState:UIControlStateNormal];
cell.pokebtnoutlet.hidden=YES;
cell.editbutnoutlet.hidden=NO;
cell.editbutnoutlet.tag = indexPath.section;
[cell.editbutnoutlet addTarget:self action:@selector(editButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[_providertbl reloadData];
}else{

[cell.pokebtnoutlet setImage:[UIImage imageNamed:@"hold"] forState:UIControlStateNormal];
cell.pokebtnoutlet.hidden=NO;
cell.editbutnoutlet.hidden=YES;
cell.pokebtnoutlet.tag = indexPath.section;
[cell.pokebtnoutlet addTarget:self action:@selector(pokeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

}
NSString *imgUrl = [NSString stringWithFormat:@"%s/presignin/clubber/getImage?clubberId=%@",urlPath,clubberid];

NSURL *imageURL=[NSURL URLWithString:imgUrl];
imgarray=[[isclassifiedarray objectAtIndex:indexPath.section]valueForKey:@"media"];
cell.profile_img.imageURL=imageURL;
cell.imgcollection_view.tag=indexPath.section;
if (imgarray.count==0) {
cell.imgcollection_view.hidden=YES;

}else{

cell.imgcollection_view.hidden=NO;
}
cell.imgcollection_view.delegate=self;
cell.imgcollection_view.dataSource=self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.imgcollection_view.allowsSelection=NO;
return cell;
}
}

Collection View 代码

    - (NSInteger)collectionView:(UICollectionView *)view
numberOfItemsInSection:(NSInteger)section {

return imgarray.count;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView
*)collectionView {
return 1;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)cv
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//isclasifiedimageCell *cell1 = nil;

cell1=[cv
dequeueReusableCellWithReuseIdentifier:@"isclasifiedimageCell"
forIndexPath:indexPath];

NSLog(@"%ld",(long)indexPath.row);

NSString *clubberid=[NSString stringWithFormat:@"%@",[[imgarray objectAtIndex:indexPath.row]valueForKey:@"idclassifieds_media"]];

NSString *clubberidtype=[NSString stringWithFormat:@"%@",[[imgarray objectAtIndex:indexPath.row]valueForKey:@"type"]];
}
else{
NSString *typeimgUrl1 = [NSString stringWithFormat:@"%s/presignin/classifieds/showMedia?idclassifieds_media=%@",urlPath,clubberid];
NSURL *imageURL=[NSURL URLWithString:typeimgUrl1];

cell1.img_view.imageURL=imageURL;
}

return cell1;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",(long)cell.imgcollection_view.tag);
mediaimgarray=[[isclassifiedarray objectAtIndex:cell.imgcollection_view.tag]valueForKey:@"media"];
NSString *cluderimgid=[NSString stringWithFormat:@"%@",[[mediaimgarray objectAtIndex:indexPath.row]valueForKey:@"idclassifieds_media"]];
// NSString *mediatypeurlstr=[NSString stringWithFormat:@"%@",[[mediaimgarray objectAtIndex:indexPath.row]valueForKey:@"idclassifieds_media"]];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
isclasifiedImgpreviewVC * isclasifiedImgpreview =
[storyboard instantiateViewControllerWithIdentifier:@"isclasifiedImgpreview"];
// isclasifiedImgpreview.mediaatype=cluderimgid;
isclasifiedImgpreview.mediaatypeurlid=cluderimgid;
[self presentViewController:isclasifiedImgpreview
animated:YES
completion:nil];

最佳答案

示例 TableView 代码:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CellTableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellCol"];
// Give Tag to CollectionView
cell.collectionView.tag = indexPath.row;
return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",(long)indexPath.row);

}

示例 ColleCtionView 代码:

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 3;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *celll = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
celll.contentView.backgroundColor = [UIColor greenColor];
return celll;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",(long)collectionView.tag);
}

关于ios - 单击tableview Cell中的Collectionview时如何找到tableview的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44382303/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com