gpt4 book ai didi

ios - 无法访问 Collection View 单元格信息

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

您好,我正在尝试通过 UIsegmentedcontrol 访问 UICollection View 单元格信息。

在 Collection View 中,我有四个标签和 UIsegmented 控件。当我点击分段控件时,我想显示标签值。

这是我的代码。

- (UIView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
cell.mySegmentedControl.tag = indexPath.row;
selectedSegment = cell.mySegmentedControl.selectedSegmentIndex;
[cell.mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
cell.caseid.text=[tmpDict objectForKey:@"CaseId"];
caseid = [tmpDict objectForKey:@"CaseId"];
}

- (void) segmentValueChanged: (UISegmentedControl *) sender {
//NSInteger index = sender.tag;
if(sender.selectedSegmentIndex == 0)
{
NSString *localcaseid = caseid; // it shows default value may be first cell value.
CollectionViewCell * cell = [[CollectionViewCell alloc]init];
NSString *localcaseid = cell.caseid.text; //it prints null value
}
else
{
}

上面的代码对我不起作用。任何帮助将不胜感激。我想显示该特定单元格的信息。

最佳答案

    if(sender.selectedSegmentIndex == 0) {
NSString *localcaseid = caseid;
NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
CollectionViewCell *cell = (CollectionViewCell *)[CollectionView cellForItemAtIndexPath:tempIndexPath];
NSString *localcaseid = cell.caseid.text;
NSLog(@"%@",localcaseid);
}
else {
}

关于ios - 无法访问 Collection View 单元格信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40236937/

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