Ios 没有标识符为';searchSegue';通过xib文件';s级
我正在使用segue(Ios 没有标识符为';searchSegue';通过xib文件';s级,ios,swift,uicollectionview,segue,Ios,Swift,Uicollectionview,Segue,我正在使用segue(searchSegue)将我的搜索屏幕(SearchViewController)连接到搜索结果页面(PhotoStreamViewController) SearchViewController是一个集合视图。每个集合视图单元在Xib文件中都有一个设计。(Xib文件的类是SearchCategoryRowCell) 目前,当我通过SearchViewController触发searchSegue时,它工作正常。但每当我通过SearchCategoryRowCell触发相同
searchSegue
)将我的搜索屏幕(SearchViewController
)连接到搜索结果页面(PhotoStreamViewController
)
SearchViewController
是一个集合视图。每个集合视图单元在Xib文件中都有一个设计。(Xib文件的类是SearchCategoryRowCell
)
目前,当我通过SearchViewController
触发searchSegue
时,它工作正常。但每当我通过SearchCategoryRowCell
触发相同的segue时,我得到的是没有标识符为“searchSegue”的segue
SearchViewController.swift
class SearchViewController: UIViewController,UISearchBarDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
...
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchRedirect(keyword: searchBar.text!)
}
func searchRedirect(keyword:String) {
performSegue(withIdentifier: "searchSegue", sender:self)
PhotoStreamViewController.searchString = keyword
navigationController?.setNavigationBarHidden(false, animated: true)
}
...
}
class SearchCategoryRowCell: UICollectionViewCell {
//the method below is triggered by a click action
@objc func searchRedirection(_ sender:UIButton) {
print("we")
print(subCategoryArray[sender.tag].name)
let searchViewcontroller = SearchViewController(nibName: "SearchViewController", bundle: nil)
searchViewcontroller.searchRedirect(keyword: "otherSearchKeyword")
}
...
}
SearchCategoryRowCell.swift
class SearchViewController: UIViewController,UISearchBarDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
...
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchRedirect(keyword: searchBar.text!)
}
func searchRedirect(keyword:String) {
performSegue(withIdentifier: "searchSegue", sender:self)
PhotoStreamViewController.searchString = keyword
navigationController?.setNavigationBarHidden(false, animated: true)
}
...
}
class SearchCategoryRowCell: UICollectionViewCell {
//the method below is triggered by a click action
@objc func searchRedirection(_ sender:UIButton) {
print("we")
print(subCategoryArray[sender.tag].name)
let searchViewcontroller = SearchViewController(nibName: "SearchViewController", bundle: nil)
searchViewcontroller.searchRedirect(keyword: "otherSearchKeyword")
}
...
}
这个
如果不是当前显示的VC,则必须在cell类中使用委托或声明self作为属性
class SearchCategoryRowCell: UICollectionViewCell {
var sear:SearchViewController?
}
ans在SearchViewController
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath) as! cellClassName
cell.sear = self
return cell;
}
//
然后可以使用呈现的对象
@objc func searchRedirection(_ sender:UIButton) {
print("we")
print(subCategoryArray[sender.tag].name)
sear?.searchRedirect(keyword: "otherSearchKeyword")
}
这个
如果不是当前显示的VC,则必须在cell类中使用委托或声明self作为属性
class SearchCategoryRowCell: UICollectionViewCell {
var sear:SearchViewController?
}
ans在SearchViewController
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath) as! cellClassName
cell.sear = self
return cell;
}
//
然后可以使用呈现的对象
@objc func searchRedirection(_ sender:UIButton) {
print("we")
print(subCategoryArray[sender.tag].name)
sear?.searchRedirect(keyword: "otherSearchKeyword")
}
你已经很好地解释了原因。你是说:
let searchViewcontroller = SearchViewController(nibName: "SearchViewController", bundle: nil)
searchViewcontroller.searchRedirect(keyword: "otherSearchKeyword")
因此,
searchViewcontroller
是在代码中实例化的一个全新的视图控制器。因此,它没有分段。带有分段的视图控制器是故事板中的一个,它是一个完全不同的视图控制器。您已经很好地解释了原因。你是说:
let searchViewcontroller = SearchViewController(nibName: "SearchViewController", bundle: nil)
searchViewcontroller.searchRedirect(keyword: "otherSearchKeyword")
因此,
searchViewcontroller
是在代码中实例化的一个全新的视图控制器。因此,它没有分段。带有分段的视图控制器是故事板中的一个,它是一个完全不同的视图控制器。这是一个很好的解决方案。它工作得很好。你是救命恩人!快乐编码:)这是一个很好的解决方案。它工作得很好。你是救命恩人!快乐编码:)