2017-03-01 2 views
0

Picture for reference미분()

내 MainViewController 3 개 용기 가지고

A가있는 tableView 포함
  | A | B | C| 

는, B가 collectionView 포함, 그리고 C는 이미지 뷰를 포함한다. A 및 C의 tableView 및 imageView는 숨겨져 있으며 A 또는 C에 포커스가있을 때만 표시되어야합니다. A 및 C의 두 가지 버튼 (tableView 및 imageView의 맨 위에 있음)도 있습니다.

내가 가지고있는 문제는 collectionView에서 A 또는 C로 포커스를 이동할 때마다 xcode가 A 또는 C 중 어느쪽에 있는지를 인식 할 수 없다는 것입니다.이 코드는 다음과 같습니다.

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { 
    super.didUpdateFocus(in: context, with: coordinator) 

    if context.nextFocusedView is UIButton && context.previouslyFocusedView is UICollectionViewCell { 
     print("Focus moved to left column") 
     } 
    } 

A의 버튼이 C의 버튼과 다르다는 것을 xcode에 어떻게 알리시겠습니까?

답변

1

가장 쉬운 방법은 그 다음에, buttonA.tag = 1처럼, 각 버튼에 buttonB.tag = 2 등을 tag을 할당 할 수 있습니다 당신의 didUpdateFocus... 당신은 이런 식으로 약간 코드를 변경하여 어떤 버튼을 확인할 수 있습니다

if let button = context.nextFocusedView as? UIButton, context.previouslyFocusedView is UICollectionViewCell { 
    switch button.tag { 
    case 1: 
     // This is button A. Do whatever you need with that info 
    case 1: 
     // This is button B... 
    etc. 
    } 
} 
+0

이것을 시도해 보니 완벽하게 작동했습니다. 감사합니다. – manohjay