TVOS UISplitviewController Focus - focus

I have a UISplitViewController on my TVOS app written in swift. I'm hiding the menu table view by setting splitViewController?.preferredDisplayMode = .secondaryOnly and I'm showing the menu by setting splitViewController?.preferredDisplayMode = .oneBesideSecondary
Issue here is when i show the menu table view, it is not getting focused and focus still is there on the detail view controller, even though viewWillAppear() of menu view controller gets called and I try setNeedsFocusUpdate(), updateFocusIfNeeded() from viewWillAppear(), indexPathForPreferredFocusedView(..) or preferredFocusEnvironments() is not getting called.
I have tried with tableView.remembersLastFocusedIndexPath = true and tableView.remembersLastFocusedIndexPath = false also and it does not work
Can some one please help

Related

iOS 11 large-title navigation bar not collapsing

The Apple guy in the What's new in Cocoa Touch WWDC video said that the new large-title navigation bar will magically hook into the top-level scroll view of the underlying view controller and collapse/expand itself automatically while scrolling up and down. (And by "magically", he probably meant that they failed to monkey patch this functionality into the already embarassing UINavigationController-UINavigationBar-UINavigationitem APIs in a usable way, so they had to resort to hooking into some heuristically chosen scroll view behind the scenes)
Even though I was prepared that this "automatic" collapse/expand wouldn't work if I deviate the slightest from the basic UINavigationController + UITableView/UICollectionView setup, it seems that even in this simplest case it doesn't work as expected.
Here's what I have:
A UITabBarController which contains a UINavigationController, which contains a UIViewController, which has a UITableView as its view. Tapping the first cell in the table will push a second view controller on the navigation stack:
No code, just the storyboard.
I've checked "Prefers large titles" for the navigation bar to activate large titles. Now, if I run the app and scroll up/down on the table view, the navigation bar stays the same - large - size; it doesn't collapse:
However, I've found that if I set the second view controller's navigation item to use the small navigation bar (by setting "Large Title" to the value "Never"), then if I open that page and navigate back, the interactive collapse magically starts working on the first page:
Am I missing something here, or is this feature not working properly? Here's the sample project I'm using: https://github.com/tzahola/iOS-11-Large-Title-Navigation-Bar
And by the way, I'm using the officially released iOS 11, not the betas.
2017-09-23 Update: I've sent a bug report to Apple, and opened a ticket on openradar.me: http://www.openradar.me/radar?id=5017601935671296
If there is any other view in addition to tableView, also make sure tableView is on the top of that view(s), right under the Safe Area:
Good news! I've just figured out that if I set "Large Titles" to "Never" on the storyboard, and then set it via code, then it works:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;
}
Seems like Apple forgot to handle the case when the navigation item has its largeTitleDisplayMode set via the Interface Builder.
So until they fix this issue, leave "Large Titles" as "Never" on storyboards, and set them via code in viewDidLoad.
You just need to do that to the first view controller. Subsequent view controllers honor the value in storyboard.
Or instead of changing anything in storyboard, do this:
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 11.0, *) {
self.navigationItem.largeTitleDisplayMode = .never
self.navigationItem.largeTitleDisplayMode = .always
}
}
No matter which language!
This is because large titles on navigation item decides whether or not to collapse on the basis of large title behaviour on previous screen navigation item title.
Make sure that addSubview(tableView) placed before others addSuview(someview)
Year 2020, iOS 13.0, this WAS NEVER mentioned here. I literally spent an hour or two for this.
Issue: Large title won't collapse when doing layout programmatically using Snapkit (an autolayout framework)
Solution: SETUP YOUR VIEWS (including navigationController stuff and tableView) inside loadView() NOT in viewDidLoad().
#TamasZahola #mohamede1945
Guys I had the same problem. I was able to resolve this issue by adding following snippet on my first View Controller of Navigation Controller
navigationController?.navigationBar.prefersLargeTitles = true
It's an odd bug. The fix is to toggle OFF prefersLargeTitles in the storyboard and to set this in viewDidLoad of your nav controller's root vc:
navigationController?.navigationBar.prefersLargeTitles = true
TableView of its container should be at the top of ViewController's view hierarchy (RootView on screenshot). Otherwise it won't work.

UINavigationController animation from view controller with prompt

I am implementing an application that uses a UINavigationController. It currently shows 3 views, each a UITableViewController. The first view that is shown only has a title, while the other two have a title and prompt. All segues are created in the storyboard, which is rather straightforward:
The problem: As soon as I animate AWAY from a view that has a prompt, the animation glitches - the title (and sometimes the back button) "fly in" from the bottom, instead of from the right.
Example: https://youtu.be/N-K8piEJ1aY (recording with slow animations turned on)
Here you can see that the animation from first to second view works fine, but from second to third view is glitchy. animating back works.
This issue seems similar to Weird animations when changing NavigationItem prompt . The conclusion in that thread was that this only occurs on iOS 7, I am running on iOS 10.0/10.1, though. The issue occurs both in simulator and on the real device.
Any ideas?
The only solution I found was an absolute hack inspired by an absolute hack inspired by Catalina T. over on this post:
Either in viewWillAppear: on the appearing VC or after calling pushViewController:animated: on the navigation controller (or I'm guessing after calling performSegueWithIdentifier:sender: add the following code:
ObjC
// This is a hack that's because UINavigationBar with prompts is broken
navigationController.navigationBarHidden = YES;
navigationController.navigationBarHidden = NO;
Swift
// This is a hack that's because UINavigationBar with prompts is broken
navigationController.isNavigationBarHidden = true
navigationController.isNavigationBarHidden = false
where navigationController is a reference to the UINavigationController that's doing all the pushing (e.g. viewController.navigationController)
EDIT: It appears now there're other weird animations that occur when popping and repushing a VC, so this answer isn't a true solution. Leaving it up so as to help someone else down a similar rabbit hole.

UIBarButtonItem is not clickable

I write an iOS app in Swift able to cast videos to chromecast. I try to add mini controller at the bottom of the phone screen. Here is a fragment of my code:
...
var castContainerVC = GCKCastContext.sharedInstance().createCastContainerControllerForViewController(self.navigationController)
castContainerVC.miniMediaControlsItemEnabled = true
UIApplication.sharedApplication().keyWindow?.frame = UIScreen.mainScreen.bounds
UIApplication.sharedApplication.keyWindow?.rootViewController = castContainerVC
UIApplication.sharedApplication.keyWindow?.makeKeyAndVisible()
...
When I run this app, I can see mini controller, but when I click on my menu navigation bar button, nothing happens (It worked before I added this code). I don't have this problem with the other two navigation bar button items. I suspect that something gets wrong when I try to assign new rootViewController, but I don't know how could I fix it.

UISearchBar in UINavigationController titleView not responding / tappable

I've got a Master-Detail project using Xcode 7 beta 4 (Swift 2.1), where both the MVC and DVC are UIViewControllers. I have a UISearchController property in the DVC, which is used to display a UISearchBar in the titleView of the DVC nav controller. This search bar is working fine on iPad, but on iPhone, when I push the DVC, I can see the UISearchBar, but it cannot be tapped or first responder.
The odd thing is if I instantiate a local UISearchController in viewDidLoad and set its searchBar as the titleView, I can interact with the UISearchBar just fine, but every time I push the view controller, I get a warning:
"Attempting to load the view of a view controller while it is deallocating is not allowed - UISearchController"
If I create a class instance of the UISearchController by creating a DVC property, then the UISearchBar isn't interactable:
self.detailViewController?.navigationItem.titleView = self.searchController.searchBar
But if I do a local variable, it's interactable (with that warning stated above):
let localSearchController = UISearchController(searchResultsController: nil)
self.detailViewController?.navigationItem.titleView = localSearchController.searchBar
This bug has completely dumbfounded me, and it only occurs on iPhone. It seems like a simple problem, and I've tried many different approaches to figure it out. Maybe someone here has an idea what's wrong. Thanks!
I was able to solve this issue by searching for definesPresentationContext in my app and deleting all the instances of it. I'm sure there may be a way to fix it without deleting.

Disable a Navigation Bar Button upon Application Launch

I have an application that requires to select a client to work with when the application is launched. I am initiating a segue from the app delegate to a modal view that allows the user to make the selection. The view has a left bar button that says "cancel" and dismissed the view. I want this to be disabled when the user first selects a client, but to be enabled all subsequent times the user opens the client select pane.
I have an IBOutlet in the select client view called cancelButton.
In my prepareForSegue method in the view controller that is launching the segue, I have
if ([segue.identifier isEqualToString:#"selectClient"]) {
if (firstSegue) {
SelectClientViewController *select = (SelectClientViewController *)segue.destinationViewController;
select.cancelButton.enabled = NO;
}
firstSegue = NO;
}
However, the button remains enabled on the first launch. Any help would be greatly appreciated.
When prepareForSegue is called the view hasn't been loaded. If you don't do anything to make it during the method then the view won't be loaded till later. If the view hasn't been loaded then the outlets aren't available (they haven't been loaded yet either). So, the problem is that the button you are trying to disable doesn't exist yet.
Set a flag on the destination controller so it disables the button in viewDidLoad or ensure that the view is loaded before you try to set any view properties.

Resources