gpt4 book ai didi

ios - 如何在 UICollectionviewcontroller 中显示文本字段?

转载 作者:行者123 更新时间:2023-11-29 04:00:45 25 4
gpt4 key购买 nike

我检查了 xcode 中的页眉部分和页 footer 分,我在 UIcollectionviewcontroller 中向该页眉添加了一个文本字段,但是当应用程序运行时,它不显示文本字段?为什么?

最佳答案

您应该子类化UICollectionReusableView,将outlet添加到子类,修改 Storyboard中标题 View 的重用标识符,并从数据源实现collectionView:viewForSupplementaryViewOfKind:atIndexPath。检查苹果文档。

例如:

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

HeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

//set the delegate of the textfield to the view controller
headerView.textField.delegate = self;

return headerView;
}

关于ios - 如何在 UICollectionviewcontroller 中显示文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15873494/

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