gpt4 book ai didi

ios - 如何快速访问另一个类的变量?

转载 作者:行者123 更新时间:2023-11-30 12:11:59 26 4
gpt4 key购买 nike

我的UserSearchController中有一个搜索栏:

class UserSearchController: UICollectionViewController, UICollectionViewDelegateFlowLayout,UISearchBarDelegate, UISearchDisplayDelegate {

lazy var searchBar: UISearchBar = {
let sb = UISearchBar()
sb.placeholder = "Search"
sb.barTintColor = UIColor.gray
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.rgb(red: 230, green: 230, blue: 230, alpha: 1)
sb.keyboardAppearance = .dark
sb.delegate = self
return sb
}()

我想从 UserSearchCv 访问并隐藏该搜索栏:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let user = filteredUsers[indexPath.item]
print(user.username)

let userProfileController = UserProfileController(collectionViewLayout: UICollectionViewFlowLayout())
(superview?.next as? UIViewController)?.navigationController?.pushViewController(userProfileController, animated: true)

UserSearchController.searchBar.isHidden = true //Something like this but it compiles an error
}

最佳答案

您需要通过对象引用而不是类名来访问该变量。试试这个-

userProfileController.searchBar.isHidden = true

关于ios - 如何快速访问另一个类的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45938486/

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