gpt4 book ai didi

IOS - UICollectionView - 通过 segue 将数据传递给 subview

转载 作者:行者123 更新时间:2023-11-28 22:07:20 25 4
gpt4 key购买 nike

我正在努力通过 UICollectionView 将数据传递给 subview - 基本上我想在 subview 中使用基于项目的相关数据填充几个 UITextField单击 - 这是我 View 的屏幕截图 -

enter image description here

这里是数组数据的片段,展示了它是如何组合在一起的——

 sightsObject *sight13 = [[sightsObject alloc] initWithsiteTitle:@"ssd"   siteSection:@"views" siteType:@"" siteSubTitle:@"" siteDescription:@"" siteMapUrl:@"docks" sitePic:@"further"];

数组目前是静态的——所以它的编译如下——

 self.sightsArray = [NSArray arrayWithObjects:sight1, sight2, sight3, sight4, sight5, sight6, sight7, sight8,sight9,sight10, sight11, sight12,sight13, nil];

self.sectionData = [NSArray arrayWithObjects:@"beatles", @"docks",@"unique",@"museums", @"Football",@"Tours",@"Views",@"Further Afield", nil];

uiCollectionView 填充如下 -

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

_selectedItemIndex = indexPath.row;


CSCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell"
forIndexPath:indexPath]
NSString *s = self.sectionData[indexPath.section];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"siteSection like %@", s];
NSArray *filteredArr = [self.sightsArray filteredArrayUsingPredicate:pred];
NSLog(@"Value of hello = %@", filteredArr);
sightsObject *rightS = filteredArr[indexPath.row];
cell.textLabel.text =rightS.siteTitle;
cell.textBrief.text = rightS.siteSubTitle;
cell.imageIco.image = [UIImage imageNamed:rightS.sitePic];

return cell;

我已经在这个方法中存储了选择的索引路径——

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {


self.selectedItemIndex = indexPath.row; //stored as NSInteger

}

最后我尝试按如下方式传递数据 -

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{


NSArray* selectedItem = [_sightsArray objectAtIndex:self.selectedItemIndex ];

SightViewController *destController = [segue destinationViewController];
destController.viewTit = selectedItem.siteTitle ;




}

但我收到一条错误消息,指出在 NSArray 上找不到属性 siteTitle..

我哪里错了?

最佳答案

你可以用

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"FirstView"]) {
NSString* selectedItem = [_sightsArray objectAtIndex:self.selectedItemIndex];
SightViewController *destController = (SightViewController *)segue.destinationViewController;
destController.selString = selectedItem;
}
}

在 desController.h 文件中将字符串变量声明为

@property(nonatomic, copy) NSString *selString;

关于IOS - UICollectionView - 通过 segue 将数据传递给 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23632332/

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