Showing posts with label apple-tv. Show all posts
Showing posts with label apple-tv. Show all posts

Friday, June 9, 2017

Implementing custom focus behaviour for UICollectionView on AppleTV

Leave a Comment

I'm trying to implement pretty straightforvard UI on tvOS and after few failures it seems like it is impossible.

I have 2 collection views with horizontal scrolling.

  • 1st - cities
  • 2nd - options

Option set is same for all cities but some options can be disabled for some cities. At least one option is available for each city.

User can select city and option for it by focusing on specific cell. Current selection is visible on screen (see labels under collection views)

UI example

What I'm trying to do is to remember selected city/option, so when I change option between thos collection views - previously selected item becomes focused (selected). That's possible to do using remembersLastFocusedIndexPath flag fo UICollectionView but collection view ignore disabled cells.

For example in attached project Option 3 is disabled for Dublin. So if user selects London, then selects Option 3, then moves focus back to cities collection view and changes selection to Dublin, then Option 3 becomes disabled (isUserInteractionEnabled is false and collectionView(_ collectionView:, canFocusItemAt indexPath:) returns false). However if remembersLastFocusedIndexPath is true - collection view ignores all of those and tries to focus disabled item. At this point UI ob collection view "broke":

broken UICollectionView

There is indexPathForPreferredFocusedView(in:) method but it's trigged only once for preferred UICollectionView even though that's isn't obvious from Apple's documentation.

Is there a way to write "custom" logic for focusing cells? What I need to implement for options collection view is to select currently selected option if it is available or first available option if currently selected option is disabled every time it gets focus. Subclassing UICollectionView should't be the way to solve that as it shouldn't know about data model.

Here you can download test project

0 Answers

Read More

Wednesday, October 5, 2016

Login Logout for ViewController and TabBarViewcontroller? APPLE TV

Leave a Comment

would someone have any experience with this type of layout? I have a Initial ViewController that is used for Login then after Login it goes to a TabBarViewController as presentViewController() from the LoginViewController. All of this works well and logout but once I log out and re-login in the same session it looks like it creates another Tabbarviewcontroller ontop and then crashes the app. Bellow is the image with the storyboard layout

let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())     let vc : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("TabBarViewController") as UIViewController     self.presentViewController(vc, animated: true, completion: nil) 

enter image description here

1 Answers

Answers 1

Does this help answer your question? http://sketchytech.blogspot.sg/2012/11/instantiate-view-controller-using.html

Possibly relevant text:

Note: if the presented view controller and the presenting view controller are the same class then do not place presentation code in viewDidAppear: because this would mean view controllers were created infinitely.

Read More

Tuesday, April 12, 2016

NSNetServiceBrowser not able to find Apple TV “occasionally”

Leave a Comment

I am using NSNetServiceBrowser to find NSNetService of Apple TV over bonjour connection. Now my code works almost every time. But every once in a while (1 out of 10 times) NSNetServiceBrowser is not able to find NSNetService of Apple TV or taking awful amount of time to find it.

Once NSNetServiceBrowser is unable to detect Apple TV, I have to restart the Apple TV and again everything starts working normally.

I am not able to understand what is the problem and how restarting the Apple TV solves it. So I am looking for any guidance or suggestion to pin point the problem.

Code for Apple TV :

service = [[NSNetService alloc] initWithDomain:@"" type:@"_test._tcp" name:@"TV ZohoShow" port:0]; [service scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; service.includesPeerToPeer = YES; if(service) {     [service setDelegate:self];     [service publishWithOptions:NSNetServiceListenForConnections];  } 

Code for iOS device:

[serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; serviceBrowser.includesPeerToPeer = YES; [serviceBrowser setDelegate:self]; [serviceBrowser searchForServicesOfType:@"_test._tcp" inDomain:@""]; 

UPDATE: It never happens when I try the connection between two iOS devices. I get the connection 100/100 times in that case. But as soon as I introduce Apple TV, I start getting those occasions where TV won't be found.

0 Answers

Read More