gpt4 book ai didi

ios - 在 CollectionView 标题单元格中访问 SearchBar - Swift

转载 作者:行者123 更新时间:2023-11-29 02:42:58 24 4
gpt4 key购买 nike

目前我在 CollectionView 标题单元格上实现了一个简单的 UICollectionReusableView 类:

class SearchBarCollectionReusableView: UICollectionReusableView {

@IBOutlet weak var searchBar:UISearchBar!
@IBOutlet weak var filterSegCtrl:UISegmentedControl!

override init(frame: CGRect) {
super.init(frame: frame)
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}

然后我将它添加到我的 UICollectionViewClass 以显示下面的标题:

override func collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!) -> UICollectionReusableView! {

var reusableview:UICollectionReusableView!

if kind == UICollectionElementKindSectionHeader {
let headerView:SearchBarCollectionReusableView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "SearchBar", forIndexPath: indexPath) as SearchBarCollectionReusableView
reusableview = headerView
}
return reusableview
}

如何访问 UISearchBar 属性,包括 UICollectionViewClass 中的委托(delegate)文本

最佳答案

我的回答假设您在 UICollectionViewClass 中有一个 SearchBarCollectionReusableView 实例,假设它是您的 UIView扩展类。

假设您的 SearchBarCollectionReusableView 变量是 searchBarCRV。由于所有实例级变量在 Swift 中都是公开的,因此您可以直接访问其实例变量。您可以通过类似的方式获得代表,

searchBarCRV.searchBar.delegate = self;

和文本...

var searchBarText = searchBarCRV.searchBar.text

... 在您的 UICollectionViewClass 中。

关于ios - 在 CollectionView 标题单元格中访问 SearchBar - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25527868/

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