More button replaces UIBarButtonItems in the Left Side of the UINavigationBar - iphone

I have a Tabbed Application which has six tabs, so as expected two of the tabs move under the "More" tab at the end. I have a refresh button I want to put in the top left corner of every tab view, but when I place these using the Storyboard, the back button with the "More" text is overwritten if I'm in one of the tabs that was moved under the More tab. The behaviour I'm trying to get is to put the refresh button NEXT to the More tab, kind of like how Apple did their tabs in the iTunes app in the attached screenshot.
I've tried looking at methods that do button placement using code but most of them seem to assume you want to create all the buttons using code and place them in an array. I haven't been able to find a way to create the More button, since I think that's generated automatically, but if there's a method I could use to add an extra button alongside it, that would do what I'm wanting.
tl;dr: Is there a way to add buttons alongside the More button?
(I'm new so I can't add screenshots, but here is a link to the screenshot I meant. http://i.stack.imgur.com/GV6M2.png)

Will you know what the index of the "More" button will be, so you could add your "Refresh" button to the button array just before it?

Found the answer! It always helps to look at the list of methods. There's a BOOL you can set called leftItemsSupplementBackButton and it is normally set to NO, but if it's set to YES it will add any buttons next to the back button instead of replacing it. Even works with Storyboard-created buttons :D
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationItem_Class/Reference/UINavigationItem.html%23//apple_ref/occ/instp/UINavigationItem/leftItemsSupplementBackButton
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(loadLoginScreen) withObject:nil];
isAnimated = YES;
[self.navigationItem setLeftItemsSupplementBackButton:YES];
}

Related

Adding Search Button to UINavigationBar : Swift

I have a ViewController1 and ViewController2. ViewController1 has a NavigationController set to it. I have a button (Custom Search Icon) on the NavigationBar. Now I press control+click and drag to ViewController2 and set it to Show. When I press it, it doesn't work. I also tried to drag the button to ViewController1 and set it as an IBAction but that doesn't work either.
What I want accomplished:
I want to create a button on the left side of the NavBar. When clicking it, I want to be add the searchbar and allow the user to search from an array. What is the best way about doing this? The search bar also has the cancel button, and if pressed the user should return back to his previous ViewController. I don't want anyone to the work for me but if you could point me to the right direction, it would be awesome.
I'm assuming by "Custom Search Icon", you mean a UIBarButtonItem in the navigation bar. If that's the case you should be able to segue to a controller using the technique you described, so you could try putting in a new UIBarButtonItem and try again.
But for the problem you're describing I might recommend a slightly different approach using UISearchController. Since it sounds like you're using storyboards, drag in the Search Bar and Search Display Controller from the object library to your controller, just below the navigation bar.
Check out UISearchController documentation:
[https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISearchController/ ]
And here's a sample project from Apple:
[https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html ]
Good luck!
Delete all the connections from the interface builder first. Clear the codes associated to the button.
Create an IBAction and put a break point to see if its called when u click the button.
If it does get called then push a new ViewController onto it,(ViewController2).
Add your search bar here on the ViewController 2.

Showing a overlaying menu when tab bar item is clicked - IOS

Thanks for reading my question!
I have a 5-part tabbar which I use for app navigation, the center tab is covered by a UIButton and is slightly larger (much like the instagram app). This works fine.
But what I want is the far right tab bar item to show a overlaying menu when clicked. I don't want it to switch to a viewcontroller with a menu. I want the menu to be displayed no matter which of the other views you're in at the moment. So I want it to act much like a button which is in the tabbar. But I have no idea how to go about doing this.
Should I use a overlaying button over the tabbaritem or should I catch the tabbarclick, but how can I prevent the view from changing in that case?
Thanks you for any help!
You need to implement UITabBarDelegate. Then override tabBar:didSelectItem: and implement your custom displaying here. See below for reference
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITabBarDelegate_Protocol/Reference/Reference.html
Then i would just make a custom UIView and fade it in when that specific tagged UITabBarItem is pressed.

How to disable backBarButtonItem displayed in current view?

After a view has been pushed onto the UINavigationController stack and is displayed I need to disable the Back button under certain circumstances, e.g., when data is being edited on that screen.
The following hides the Back button
self.navigationItem.hidesBackButton=YES;
but I need to disable it.
There are several other answers about how to hide it or suggest not displaying it in the first place, but these are not what I need to implement.
You could implement one of the delegate methods for your navigationController's navigation bar delegate. Take a look at the [UINavigationBarDelegate navigationBar:shouldPopItem:] method.
Returning YES or NO from this method will enable or disable the back button.
You could implement one leftBarButtonItem (invisible and without effect)
add it into your current view (self.navigationItem.leftBarButtonItem)
and remove it to access your backButton.
If you're fine that the whole navigation bar is disabled, an easy solution is
self.navigationController.navigationBar.userInteractionEnabled = NO;
Of course this doesn't work if you have other bar buttons that you want to keep enabled.

UITabBarItem does not register click on the icon

I have four UITabBarItem's. Each has a label and custom icon. My AppDelegate uses the UITabBarDelegate protocol and every click on a tabbaritem is logged to the console so I can see what is happening.
The only way to select a tabbaritem is to click on the label. If I click anywhere else on the button area, including the icon, nothing happens at all.
Have you come across anything similar?
Well, I found the issue. Whenever a tab was clicked and a new view was programatically inserted, that view was placed on top of the tabbar, but since it's background was transparent I could not see it. So half of the tab bar was covered by another view. By making sure to bringSubviewToFront: the problem could be solved. Thank you everyone who tried to help.

Where should I "save" changes in my iPhone view to 'create new' of an object?

I have a view that creates a new core data managed object, and fills in all the required properties and also allows optional ones. I originally had a "Done" button on the top left, and when that was pressed, I validated the object then saved and removed the view.
Now I have an edit/done type setup on the top right, so sometimes there are two identical "Done" buttons on the top of the view. I want to switch the left side button so that it just has the normal "Back" button, then somehow validate and stop the view from being removed if it doesn't validate. I can't find any way to capture the method called by that back button and modify it, and viewWillDisappear doesn't work cause there's no way to abort the disappearing.
How can I make this work? I need to validate this, then save, then remove the view if validate and save worked only.
It sounds like your view is a perfect candidate to be pushed modally instead of through the navigation controller stack.
Push the view that creates your NSManagedObject modally:
[self presentModalViewController:yourViewController animated:YES]
Then continue to use your top right EDIT/DONE button for editing/validation as you currently are and when validation is successful simply save your object and dismiss the modal view controller from the parent view controller:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
For more details check http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
If you still want to use a button on the left hand side perhaps you can change the right button to say EDIT/CANCEL and add a DONE button on the left side that is only visible when you're not in EDIT mode. If appropriate you can point the DONE button to run through the same validation process before dismissing the modal view using the code above but it probably makes sense that the EDIT/CANCEL button takes care of it.
I hope this helps.
Rog
There is no documented way to intercept the standard back button of UINavigationController. If you want this functionality, your only option would be to customize leftBarButtonItem with a custom button.
When the user taps that button, you can first validate your object and then call popViewControllerAnimated:.
It's hard to mimic the look of the built-in back button, though.