0

을 순간 나는 CollectionView 헤더 셀을 구현하는 간단한 UICollectionReusableView 클래스가 :CollectionView 헤더 셀에 SearchBar에 액세스 스위프트

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 속성에 대한 액세스 권한을 얻는 방법 nd 텍스트UICollectionViewClass?

답변

1

귀하의 SearchBarCollectionReusableView의 인스턴스가 내부에 있으며 이는 귀하의 UIView 확장 클래스라는 가정하에 응답하고 있습니다.

SearchBarCollectionReusableView 변수가 searchBarCRV이라고 가정합니다. 모든 인스턴스 수준 변수는 Swift에서 공용이므로 인스턴스 변수에 직접 액세스 할 수 있습니다. 당신은 당신의 UICollectionViewClass 안에 ...와, 뭔가 등으로

var searchBarText = searchBarCRV.searchBar.text

을 ...

searchBarCRV.searchBar.delegate = self;

및 텍스트 대표를 얻을 수 있습니다.

관련 문제