2016-06-29 7 views
0

2 개의 빠른 파일이 있는데 그 중 하나는 내 HomeViewController이고 다른 하나는 내 EventCollectionViewCell입니다. 두 번째에는 IBOutlet = informationView : UIView가 있고 HomeViewController에서이 정보에 액세스하려고합니다.다른 클래스의 IBOutlet에 액세스

어떨까요? 는 KS

+0

함께 IBOutlet에 액세스하려면 (self.searchHeaderView.searchTextField.text.length < = 0) {

 self.searchHeaderView.clearButton.hidden = YES; 

} 또, 액세스해야하는 경우 먼저 해당 ViewController의 객체. 그러나 이것은 정말로 나쁜 습관입니다. 두 번째 VC에서 첫 번째 VC를 변경하려면 대신 위임 패턴을 사용해야합니다. – NSNoob

답변

0

그럼 내가 HomeViewController에서 당신이 UICollectionView하고 그것을위한 데이터 소스 역할은 다음 collectionView 데이터 소스에서 당신이 할 수 있다고 가정, 사전에 감사 :

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! EventCollectionViewCell 

    //Here you can access the IBOulets define in your cell 
    cell.informationView.backgroundColor = UIColor.greenColor() 

    return cell 
} 

편집 :

문제점 : 셀을 탭하면 셀 내부에 오버레이를 표시하려고합니다.

해결 방법 :이 활동의 ​​여부합니다 (informationView) 경우 당신은 상태를 유지하기 위해 당신에게 데이터 모델을 필요 ItemCell이 (될 수있는 경우 이벤트에) 내 모델이라고 가정합니다

class ItemCell{ 
    var active:Bool = false 
} 

에서 collectionView:cellForRowAtIndexPath:, 당신은 그 오버레이, 쇼를 그의 현재 모델의 상태 및 기반을 확인하거나 숨길려고 :

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! EventCollectionViewCell 

    let event = self.data[indexPath.row] 
    //Here you can access the IBOulets define in your cell 
    cell.informationView.hidden = !event.active 

    return cell 
} 

그런 다음 마지막 단계로, 때마다 당신이 셀을 선택합니다 (func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) 방법), 당신은 당신의 모델의 상태를 업데이트하는거야 :

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){ 
    let event = self.data[indexPath.row] 
    event.active = !event.active 
    collectionView.reloadData() 
} 

샘플 프로젝트 : 당신은 인터페이스 빌더에서 셀을 만드는 경우 https://github.com/Abreu0101/SampleTap

+0

José가 당신의 빠른 반응에 감사드립니다. 코드가 작동했지만 문제가 있습니다. 내 정보보기에 Tap 제스처 인식기를 추가하고 싶습니다. 내 앱이 깨져서이 오류가 발생합니다. *** 캐치되지 않은 예외로 인해 앱이 종료됩니다. 'NSInvalidArgumentException', 이유 : '- [wallhab.HomeViewController Tapp의가] : 인식 할 수없는 선택기 인스턴스 0x1365c14d0 '내가 사용하는 코드는 – kstefanou

+0

로 전송 : 'aSelector을 보자 선택기 = "Tapp의"를 tapGesture = UITapGestureRecognizer하자 (대상 : 자기 행동 : aSelector) tapGesture.numberOfTapsRequired = collectionView합니다. addGestureRecognizer (tapGesture)' 그리고 당신이 나에게로 내 collectionView 기능이 코드를 추가 를'FUNC Tapp의가() { 인쇄 ("탭 탭") cell.informationView.hidden = 거짓 }' – kstefanou

+0

당신이 할 수 도와주세요, 제발 ? – kstefanou

0

호세 대답 것에 따라. Identity Inspector의 셀 클래스를 EventCollectionViewCell로 설정하고 셀 식별자를 Jose가 지정한 "cellIdentifier"로 설정합니다.

0

해당 셀에 대한 속성을 선언하고 해당 개체를 통해 IbOutlet에 액세스합니다.

@property (비 원자력, 강함) MSSearchHeaderView * searchHeaderView;

{

 self.searchHeaderView.clearButton.hidden = NO; 

}