I have a UIViewController embedded in a popover. This controller has two subviews, a UINavigationBar and a MapView. I try to implement the new search Controller i.e. UISearchController as UISearchDisplayController is deprecated in iOS8.
When I click in the search bar (displaying two scopes), everything is all right, and the navigation bar is still visible. But when I start typing in the search bar, the navigation bar and the keyboard disappear, replaced by a dim map view. I tried to add self.searchController.hidesNavigationBarDuringPresentation = NO; in the updateSearchResultsForSearchController: method as well as searchBarShoulBeginEditing: method, but got no result. (note that the controller viewDidLoad defines self.definesPresentationContext = YES;)
Any idea to force navigation being displayed anytime?
First set this property self.definesPresentationContext = YES; in ViewDidLoad. Then implement searchBarTextShouldBeginEditing and searchBarTextDidBeginEditing methods as such:
-(void)searchBarTextShouldBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];
searchControllerMain.hidesNavigationBarDuringPresentation = NO;
}
It will work!!
Related
I embedded tableviewcontroller into a navigation controller, set the title, but it does not show when I run the app.
What is wrong?
This is the setting of the tableviewcontroller
Here is the setting of the navigation controller
First check, your NavVC must be initial VC.
If not then try this piece of code
-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
you must be presenting the plain table view instead of navigation controller. What you need to do is make you tableview as root view for a navigation controller and present the navigation controller.
var nav: UINavigationController = UINavigationController(rootViewController: vc)
//then present the nav
Change the initial VC from Navigation Controller to your TableViewController
I did not set the StoryboardId for Navigation controller.
I am trying to create a preferences panel for my app using storyboards and the new NSTabViewController class.
I can get it working, but the transition setting in the storyboard seems to be ignored. It just jumps from one tab to the next, with the size of the window changing instantaneously.
I thought it might depend on whether I use autolayout or not, but it didn't seem to change the transition behavior when I toggled it.
I also have the 'Propagates title' setting checked. I had expected that it would take the label of the tab item, or the title of the view controller, and propagate that as the window title, but it doesn't seem to do that.
Anyone got this to work?
Here is a simple sample app I am testing with: https://www.dropbox.com/s/roxaplxy5gtlqns/Again.zip?dl=0
Update: Got this working thanks to Pierre. Ended up making a nice transitioning preferences window by subclassing NSTabViewController as follows:
#implementation MCPreferencesTabViewController
-(void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
[super tabView:tabView willSelectTabViewItem:tabViewItem];
NSTabViewItem *currentTabItem = tabView.selectedTabViewItem;
currentTabItem.view.hidden = YES;
tabViewItem.view.hidden = YES;
NSWindow *window = self.view.window;
NSSize contentSize = tabViewItem.view.fittingSize;
NSSize newWindowSize = [window frameRectForContentRect:(CGRect){CGPointZero, contentSize}].size;
NSRect frame = [window frame];
frame.origin.y += frame.size.height;
frame.origin.y -= newWindowSize.height;
frame.size = newWindowSize;
[self.view.window setFrame:frame display:NO animate:YES];
}
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
[super tabView:tabView didSelectTabViewItem:tabViewItem];
tabViewItem.view.hidden = NO;
}
#end
You need to make the NSTabViewController the delegate of the NSTabView.
In Interface Builder, control-drag from No Shadow Tab View to Tab View Controller and set the delegate outlet.
One would expect Interface Builder to set this up correctly when creating a new tab view controller. It does not.
Please note that this was true until Xcode 9.
Since Xcode 9, you need to remove (or not add it) this line:
self.tabView.delegate = self
otherwise you will receive an error:
*** Assertion failure in -[YourApp.CustomTabView setDelegate:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.0.100/AppKit.subproj/NSTabView.m:2766
2017-10-25 19:29:06.301282+0200 YourApp[23106:5687795] Failed to set (contentViewController) user defined inspected property on (NSWindow):
A TabView managed by a TabViewController cannot have its delegate modified
Or in viewDidLoad() for the NSTabViewController, include
self.tabView.delegate = self
How to implement: I have UIBarButtonItem with a search icon, after I click on it, I want to show the search bar in navigation bar and on click cancel button in search bar, I want to show navigation bar without search and with buttons and title like in IOS 7 calendar app.
Setup an action for your search button to present a UISearchController. See the Search > Present Over Navigation Bar demo in Apple's UICatalog sample code:
- (IBAction)searchButtonClicked:(UIBarButtonItem *)sender {
// Create the search results view controller and use it for the UISearchController.
AAPLSearchResultsViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:AAPLSearchResultsViewControllerStoryboardIdentifier];
// Create the search controller and make it perform the results updating.
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = searchResultsController;
self.searchController.hidesNavigationBarDuringPresentation = NO;
// Present the view controller.
[self presentViewController:self.searchController animated:YES completion:nil];
}
In trying to attempt to use Apple's UIViewController containment I have encountered a problem with animating the transition between two UIViewControllers.
Here is the set up... I have created a UITabBarController and within one of the tabs I have created a UIViewController as a container. This ViewController manages the transition between a UIViewController and a UINavigationController. The before view is:
When the Next button is tapped the view begins it's transition with a flipFromRight transition. During the transition, the Navigation bar is in "to" view but is located 20pixels down from the top edge of the view. Picture below:
The green is the background color of the container view. Once the new view completes the transition, the Navigation bar snaps up to the top of the view and the final result is:
The time to snap in place is independent of the duration of the animation. I achieve the final state that I want, but the transition is a problem.
I have instrumented the viewController lifecycle and the frames of the Navigation bar and the UITableView are as specified in the XIB. The xib looks like this:
Here is the code:
In -viewDidLoad -
_fromVC = [[FromVC alloc] initWithNibName:#"FromVC" bundle:nil delegate:self];
[self addChildViewController:_fromVC];
[self.view addSubview:_fromVC.view];
[_fromVC didMoveToParentViewController:self];
In my button handler -
- (void)buttonSelected
{
//
// Create the "to" View controller
//
ToVC *toVC = [[ToVC alloc] initWithNibName:#"ToVC" bundle:nil];
//
// Create the navigation controller for the study activity
//
_toNavCon = [[UINavigationController alloc] initWithRootViewController:toVC];
[self addChildViewController:_toNavCon];
[_fromVC willMoveToParentViewController:nil];
[self transitionFromViewController:_fromVC
toViewController:_toNavCon
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromRight
animations:nil
completion:^(BOOL finished) {
[_fromVC removeFromParentViewController];
[_toNavCon didMoveToParentViewController:self];
}];
}
There is no code in "to" view controller that changes the appearance of the view controller.
Another bit of information... When I "toggle In-Call status bar" in the simulator the gap at the top of the navigation bar is the height of the In-Call status bar.
I have looked at everything on the web and there is nothing that helps. Has anyone seen this and has anyone fixed it?
I did find an answer!! Subclass UINavigationController and override
- (BOOL)wantsFullScreenLayout{
return NO;
}
Apparently, UINavigationController and UITabController always want the full screen (default YES) - adjusting for the status bar - and you can not set this property any other way. It has been working for me.
I have a PopoverController view that allows a user to download a file. On button press, the popOver view will expand in size, display download status, and the main view controller will be obscured by an unhidden "cover" view that has been added to the PopoverController's "passThroughViews" property so that the user can not accidentally dismiss the pop over while the file is downloading.
My problem is that, in storyboards, my main viewController is embedded in a Navigation Controller. I can't seem to cover the navigation controller's bar with a view in the storyboard, and if the user presses anywhere on the navigation bar then the popover will disappear and the user will lose the download's progress bar.
How do I either cover up the navigation bar with my "cover" view, or how do I add the navigation bar's view to my popOverController's passThroughViews?
Opening the Popover from the main viewController:
- (IBAction)openDataOptionsPopOver:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
PopOverViewController *optionsWindow = [storyboard instantiateViewControllerWithIdentifier:#"dataOptions"];
self.popUp = [[UIPopoverController alloc] initWithContentViewController:optionsWindow];
[self.popUp setDelegate:self];
[nextNavButton setEnabled:NO]; //Disabling barButtonItem on the navigationController
optionsWindow.containerPopOver = self.popUp; //Pointer to the popover, to resize it later.
optionsWindow.coverView = self.coverView; //Pointer to the coverView, to (un)hide later
[popUp presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Setting the passThroughViews property inside of the PopoverViewController:
//Expands the popOver on press of "refreshFileButton" to display progressView
-(void) explodeWindow
{
//setting self.navigationController.view and ...visibleViewController.view here didn't seem to work ...
[containerPopOver setPassthroughViews:[NSArray arrayWithObjects:coverView, nil]];
[containerPopOver setPopoverContentSize:CGSizeMake(600, 400) animated:YES];
[titleBarItem setTitle:#"Downloading File. Please Wait ..."];
[refreshFileButton setHidden:YES];
[progressView setHidden:NO];
[downloadLabel setHidden:NO];
[coverView setHidden:NO];
[progressView setProgress:0.0 animated:NO];
}
I've tried adding self.navigationController.view to passThroughViews with no success--it actually turns out to be a null pointer. And I can't seem to place a UIView at any level in storyboards that will cover all my controls without obscuring the popOver. What am I missing here? And thanks for reading.
Edit:
As Aglaia points out below out, implementing the following, and avoiding passThroughViews, is probably the best way to do this.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
//Don't dismiss our popover when the view covering our controls is present
if([coverView isHidden]){
return YES;
}else{
return NO;
}
}
Maybe there is something I am missing, but why don′t you just implement a new view controller with its navigation bar set to none and present it modally on button press? Then when the download is finished you just dismiss the view controller.
If you want the user to see the underlying view you can use a UIAlertView instead.
Alternatively set you view controller as the delegate of the popover controller and forbid the user to dismiss your popover on touch outside through
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Then when you want to dismiss it call dismissPopoverAnimated:
to cover the whole screen including navigation bar:
[myView setFrame:[[UIScreen mainScreen] bounds];
[self.navigationController.view addSubview:myView];