PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] How can I get a specific button running on tvOS (AppleTV) to take focus? (Objective C)

 September 29, 2022     focus, objective-c, tvos     No comments   

Issue

The project have some views with different buttons. When I hide a view and show the other view, I can't get the focus on my button.

I think is related to setNeedsFocusUpdate. I have read the Apple doc. There is not any example.

Does anyone know how to do it and put an example (Objective C)?


Solution

You need to override preferredFocusedView, and when you are hiding one view and showing there call this method setNeedsFocusUpdate, your preferredFocusedView implementation should be something like this

- (UIView *)preferredFocusedView
{
    // Add your logic here, it could be more complicated then what is below
    if (view1.hidden)
    {
        return _button;
    }
    else 
    {
        return _button2
    }
}

And if you want to make custom view get focus, override canBecomeFocused method and return true

Edit

You can use add a breakpoint and execute this command po [buttonYouWantToFocus _whyIsThisViewNotFocusable] it will tell you why its not focusable.



Answered By - Adnan Aftab
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing