ToolBar in Navigation Based Application - objective-c

Since my last post I'm moving ahead. My Navigation Based Application has to contain toolbar at the bottom of UIViewController. I googled a couple of hours and found a lot of regarding stuff.... well at least I've found this page:
http://frog.io/blog/ios-toolbars
Implemented and got my toolbar buckled up. There's only problem that no single bar button item is visible. So, I need two advices:
How to make em visible?
Is this approach correct enough? I mean wouldn't it be rejected by Apple?

Adding a UIToolbar to a UINavigationController based application is actually deceptively easy. Per the UINavigationController Class Reference, there is a built-in UIToolbar, which is hidden by default.
To show the toolbar try this in your UIViewController subclass:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self navigationController] setToolbarHidden:NO animated:YES];
}
To add items to the toolbar, you simply use the - (void)setToolbarItems:(NSArray *)toolbarItems animated:(BOOL)animated during - (void)viewDidLoad or similar.
You will need to remember to hide the toolbar during - (void)viewDidDisappear:(BOOL)animated unless you want it to hang around as other UIViewControllers are pushed and popped.

Related

iOS7 Keyboard Behavior with SearchBar/UITableView: Offset on secondary view appearances

Problem
I am having a rather big issue with the iOS7 keyboard appearance. I have a Searchbar on a UIViewController with TableView Delegation/Data Source setup (I am using the self.searchDisplayController delegates as well). I segue from this scene to a prototype tableview to show the results.
Here is the issue:
On first load I can see the keyboard being displayed when I tap into the text field of the UISearchBar. I can type and perform a search with the results being shown in the next scene.
I've added NSNotifications to view the keyboard properties in local methods keyboardWillShow and keyboardWasShown. I can see on the first scene appearance (after the view is completely loaded):
I segue to the result tableview at this point and when I navigate back and touch the text field, my keyboard shows up either fully or partially off-screen:
When I look at the keyboardWillShow notification at this point I can see that my keyboard values are incorrect:
I've researched and tried many possibilities including:
Added the following to my main view controller:
-(BOOL)canResignFirstResponder
{
return YES;
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
Configured the following in my view did load
self.searchDisplayController.searchBar.spellCheckingType = UITextSpellCheckingTypeNo;
self.searchDisplayController.searchBar.autocapitalizationType= UITextAutocapitalizationTypeNone;
self.searchDisplayController.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchDisplayController.searchBar.keyboardType = UIKeyboardTypeDefault;
Put in standard stubs for:
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
I've noticed that if I choose a Partial Curl as my segue mode, the keyboard remains accessible when I roll back to the main view controller (but then it was never fully off screen in that case). However if I move from the results tableview to a detail scene and then navigate back to the main view controller, the keyboard appears off-screen again.
Question
Is there a method I can use to intercept the misplaced keyboard so that it displays in the default location?
NB: Along these lines, I have created a NSDictionary property to hold the initial userInfo values with the correct keyboard placement. I am not sure how to reassign these values to get the keyboard to return to it's original placement.
BTW - This seems a bit of a hack to get the keyboard fixed due to a bug in IB, is there some other way that I can try to remedy the situation?
Thanks in advance for any feedback!
Solution
This was such an obscure issue that I'm sharing the solution to save the next person some effort. Like most programming issues, it turns out this one was self-inflicted. In my original iteration of this project I had turned off rotational support as I am learning auto-layout and I wanted to ease into the transition from Springs and Struts. Somehow between the start of the project and the code release I ended up with this bit of code in the Main Scenes' View Controller.
//BAD
- (NSUInteger) supportedInterfaceOrientations
{
return !UIInterfaceOrientationPortraitUpsideDown;
}
instead of returning a valid enumeration like...
//OK
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}

Scroll uitableview with slide uitableviewcell

I've done a custom UITableViewCell` with a front view and a back view for doing something like mailbox.
I've added the gestureRecognizer to scroll the front view so
self.slideRecognizer =
[[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(slide:)];
[self.slideRecognizer setDelegate:self];
[self addGestureRecognizer:self.slideRecognizer];
The problem is that I cant scroll the UITableView down unless I tap outside the UITableViewCell (for example on UITableView header) and go down.
There should be something to add or edit in my method
- (void)slide:(UIPanGestureRecognizer *)panRecognizer
It's true?
THAT'S THE SOLUTION FOR ME ____________________________________________________________________________
Based on Simon's link, I've added this code in my tableViewController and in my custom cell
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:
(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
The problem was that assigning the custom pan gestureRecognizer I've invalidating the default one.
I would take a look at this question which seems quite similar. It sounds as though the gesture is only being captured by that cell and not passed through.
Tell ScrollView to Scroll after other pan gesture
I'm not sure if this is exactly the same issue as yours however. You should post more code.
On a side note, personally as a developer and a user I find scrolling elements inside scrolling elements to be every irritating to use. From a usability perspective I would consider a redesign. Thats only my opinion however.

Is there a way to remove UITabBar/or do something for a UIViewController and ALL other UIViewcontroller added on top of UINavigationBar Stack?

This is the approach I am using:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.tabBarController hideTabBar];
}
-(void) viewWillDisappear:(BOOL)animated
{
[self.tabBarController showTabBar];
[super viewWillDisappear:animated];
}
With this approach if I add something to the navigation stack the UITabBar will be shown again.
What about if I want UITabBar to be only shown when user navigate away to another tab or press back button, so not all cases of viewWillDisappear?
Pushing a UIViewController on top of navigation stack shouldn't change that
You can use NSNotification as well, so whenever you require to hide tab bar. At that moment fire that notification which will show/hide your tab bar.
Benifit of NSNotification is, you can fire that in entire application life cycle, and it does not be specific to any view controller or any class. One can use that independently from any class/view controller.
Hope this is what you are looking for.
Regards,
Mrunal
Do following in your view will appear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.tabBarController.tabBarController.tabBar.hidden=TRUE;
}
This will remove tabbar from the particular controller . and navigation stack will not change.
This is what I did
At viewDidDisappear, I check if self.navigationController is empty. If it's empty I simply know that the view has been poped out of navigationController, which is the only way to get that view out of window hierarchy.

UIPageViewController Traps All UITapGestureRecognizer Events

It's been a long day at the keyboard so I'm reaching out :-)
I have a UIPageViewController in a typical implementation that basically follows Apple's standard template. I am trying to add an overlay that will allow the user to do things like touch a button to jump to certain pages or dismiss the view controller to go to another part of the app.
My problem is that the UIPageViewController is trapping all events from my overlay subview and I am struggling to find a workable solution.
Here's some code to help the example...
In viewDidLoad
// Page creation, pageViewController creation etc....
self.pageViewController.delegate = self;
[self.pageViewController setViewControllers:pagesArray
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:NULL];
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
// self.overlay being the overlay view
if (!self.overlay)
{
self.overlay = [[MyOverlayClass alloc] init]; // Gets frame etc from class init
[self.view addSubview:self.overlay];
}
This all works great. The overlay gets created, it gets show over the top of the pages of the UIPageViewController as you would expect. When pages flip, they flip underneath the overlay - again just as you would expect.
However, the UIButtons within the self.overlay view never get the tap events. The UIPageViewController responds to all events.
I have tried overriding -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch per the suggestions here without success.
UIPageViewController Gesture recognizers
I have tried manually trapping all events and handling them myself - doesn't work (and to be honest even if it did it would seem like a bit of a hack).
Does anyone have a suggestion on how to trap the events or maybe a better approach to using an overlay over the top of the UIPageViewController.
Any and all help very much appreciated!!
Try to iterate through UIPageViewController.GestureRecognizers and assign self as a delegate for those gesture and implement
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
Your code may be like this:
In viewDidLoad
for (UIGestureRecognizer * gesRecog in self.pageViewController.gestureRecognizers)
{
gesRecog.delegate = self;
}
And add the following method:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view != self.pageViewController.view]
{
return NO;
}
return YES;
}
The documented way to prevent the UIPageViewController from scrolling is to not assign the dataSource property. If you assign the data source it will move into 'gesture-based' navigation mode which is what you're trying to prevent.
Without a data source you manually provide view controllers when you want to with setViewControllers:direction:animated:completion method and it will move between view controllers on demand.
The above can be deduced from Apple's documentation of UIPageViewController (Overview, second paragraph):
To support gesture-based navigation, you must provide your view controllers using a data source object.

How to load a SplitViewController in a universal app

This is probably a straight forward problem, but I for some reason cannot get it to work.
I have an universal app, with icons on the start screen (TTLauncher) and use TTNavigator to push in view controllers.
On one of the icons a normal tableView is loaded (for the iPhone). As that is not nice for the iPad, I want to load that same tableView (if possible, as it has all the logic in it, I can adjust the code to include the required code for the splitview).
But how do I do that?
I created a UIViewController (called SplitViewController), with a XIB in which I included the SplitViewController, and I made the class for the RootViewContorller of the splitview my custom TableViewController..
I thought it would work if I added the view to the TTNavigator, but nothing happens:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"TEST!");
TTNavigator* navigator = [TTNavigator navigator];
[[navigator window] addSubview:splitViewController.view];
}
(Test is called)
I finally did try:
- (void)viewDidLoad
{
[super viewDidLoad];
//[self setView:splitViewController.view];
[window addSubview:splitViewController.view];
}
But still nothing happens. I think it is obvious that I don't understand how this works...
Any tips? Or how can I better describe this, I assume, simple problem?