2016-06-15 4 views
0

Я работаю над приложением tvOS & с использованием UISegmentedControl. На didUpdateFocusInContext я был следующий код, чтобы изменить образ UISegment как -Использование незаявленного типа UISegment swif tvOS

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) 
{ 
    if let previousItem = context.previouslyFocusedView as! UISegment  
      { 
      if previousItem.selectedSegmentIndex == 0  
       {  
       previousItem.insertSegmentWithImage(UIImage(named: "white_save_star.png"), atIndex: previousItem.selectedSegmentIndex, animated: false)  
       }  
       else if previousItem.selectedSegmentIndex == 1  
       {  
       previousItem.insertSegmentWithImage(UIImage(named: "white_goto-arrow.png"), atIndex: previousItem.selectedSegmentIndex, animated: false)  
       }   

      }  
    if let nextItem = context.nextFocusedView as? UISegment  
      {  
       if nextItem.selectedSegmentIndex == 0  
       {  
        nextItem.insertSegmentWithImage(UIImage(named: "Blue_save_star.png"), atIndex: nextItem.selectedSegmentIndex, animated: false)  
       }  
       else if nextItem.selectedSegmentIndex == 1  
       {  
        nextItem.insertSegmentWithImage(UIImage(named: "Blue_goto-arrow.png"), atIndex: nextItem.selectedSegmentIndex, animated: false) 

     } 
     }  
     } 

но получить следующее сообщение об ошибке use of undeclared type UISegment

при печати po context.previouslyFocusedView

result - 
▿ Optional<UIView> 

    - Some : <UISegment: 0x7f861c87da10; frame = (0 0; 300 70); opaque = NO; layer = <CALayer: 0x7f861c87e180>> 

, как вы можете видеть на выходе становится ясно, что UISegment класс существует.

любая помощь будет оценена

+0

И у вас есть 'импорта UIKit'? – Droppy

+0

Да, у меня был импорт UIKit –

+0

Вы нашли какой-либо публичный интерфейс для 'UISegment'? Насколько я могу судить, они всегда упоминаются как значения индекса внутри элемента управления. 'selectedSegmentIndex' - это метод' UISegmentedControl'. –

ответ

0

Вот то, что работает

if String(describing: type(of: context.nextFocusedView!)) == "UISegment"{ 
     //handle segment focus 
} 
Смежные вопросы