Where is UIButtonTypeInfoLight? - ios5

I'm looking for the UIButtonTypeInfoLight choice in the identifier list for button bar items, and I'm not seeing it. So, two questions.
Is it just missing and I'll have to create it manually, in code? I'm wondering why they would omit it.
Assuming I do have to create the button manually, to call a segue from it,do I need to manually perform the segue rather than using the storyboard?
I'm assuming I'd do this [self performSegueWithIdentifier:#"ShowChecklist" sender:nil]; from the method that my button is calling.
The code that created my button is
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:#selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[self.navigationItem setRightBarButtonItem:modalButton animated:YES];
So, Is this a common pattern? Am I doing something weird and nonstandard? It just seems to me to be weird that if my BarButton were just a custom button that said "info" I could create it and wire it up all in the Storyboard... but for this one, I have to doit all in code.

UIButtonTypeInfoLight is a UIButton. Button bar items are UIBarButtonItems. They have nothing to do with each other. You're just confusing apples and oranges.
However, a UIBarButtonItem can contain a UIButton. (That's merely by virtue of the fact that it can contain any UIView.) So drag a UIButton into a toolbar. What you get is a UIBarButtonItem containing a UIButton. If you double-click the UIBarButtonItem, you get the UIButton. Now you can set the button's type.

Related

how to customize bar button but keep the segue?

I have added a bar button item in my navigation bar and linked a segue from the button to another view controller.
Now I tried to custmize the look of this button by
UIButton *mapButton=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
[mapButton setImage:[UIImage imageNamed:#"map.png"] forState:(UIControlStateNormal)];
[mapButton setShowsTouchWhenHighlighted:YES];
[showAllButton setCustomView:mapButton];
The segue is no longer being called when I tap on it. What went wrong?
Thanks!
Leo
You can manually make a call to perform the segue, like this:
[self performSegueWithIdentifier:#"pushDeviceDetail" sender:self];
So if you set a target and selector on your button, and call that within the selector, you should be able to perform the segue.
Just remember to name your segue in interface builder to be able to do this, and then include that identifier in the call you make.
well, for one thing, you don't add a target to this new mapButton.
Not familiar with storyboards but I'm sure this new button doesn't work if you don't add a target and selector...

Adding a button to a cell

In Navigation Bar you get a Arrow shaped Back button similar to this image. (According to this image the arrow is named folders)
I need to add this Arrow shaped bar button on to a cell. Is this possible ? How can i do this programatically ?
The navigation controller back button (with the arrow appearance) can only be added using code to a navigation bar - by setting the back bar button property of the navigation item of the previous controller in the stack.
You can't add this button to a table cell, and frankly it would look a little odd - what does it do? Does each cell go "back" to a different screen? Apple aren't usually keen on you repurposing existing UI elements to mean something other than the standard.
There is no built in UIButton or UIBarButtonItem that will give you that appearance, therefore you will have to create your own image and use that as the background for a custom button which you can then add to your cell.
You can take a custom button and can set background as an image which is arrow shaped.
if you are using navigation controller-
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[[self navigationController] pushViewController:myViewController animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Folders" style:UIBarButtonItemStyleBack target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[myViewController release];
You can take custom table cell to prepare table view. In that custom table cell you will be able to add button and IBaction. You can take help from this tutorial on how to create UITableCell and then UITableView.

How to make UINavigationItem backBarButtonItem rectangular?

How can set self.navigationItem.backBarButtonItem of my RootViewController, so that the back button is rectangular instead of having a back arrow? I want to do this because I'm using a custom backBarButtonItem with an image of a grid of four squares (like the nine-square-gird image that the Facebook iPhone app uses for its home button).
Currently, in -[RootViewController initWitNibName:bundle:], I do:
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"go-home.png"]
style:UIBarButtonItemStylePlain
target:nil action:NULL];
Note: This does not cause a memory leak as I'm using ARC.
But, this makes the button have a left arrow. Is there a simple fix to make the button rectangular on all sides?
I know I could set the leftBarButtonItem for all of the view controllers that can get pushed from the RootViewController, but there are like five different options, so that'd be a lot of repetition. I guess I could make a method, e.g., +[Utils homeBarButtonItem], that creates the button above and then call self.navigationItem.leftBarButtonItem = [Utils homeBarButtonItem]; in each of the five view controllers' -viewDidLoad methods, but I'm wondering if there's a simple fix I'm missing.
Sadly the only way, as you suggest, is to use a leftBarButtonItem and use a button builder utility class.
Set the action of your leftBarButtonItem to pop the view controller and you're done.
[self.navigationController popViewControllerAnimated:YES];

UIBarButtonItem tintColor with UINavigationController

I have a navigation controller with 2 UIBarButtonItems in my navigation bar. I want to change the tint color only for the one on the right. I have found a way in static to do that:
[[self.navigationController.navigationBar.subviews objectAtIndex:2] setTintColor:[UIColor redColor]];
The problem is when I push a controller into my navigation controller to display another view, when I come back to the root view where my right navigation bar button is supposed to have a custom color, the color of the button is back to its default. And when I click again on it, the app crashes. It says it cannot change the tint color, like if the index for this element in my navigation bar changed.
I have tried other technics found on the internet, but they all failed when I use the navigation controller and come back to the root controller...
Any idea?
Thanks!
Edit 1:
I would like a bordered style button in my UINavigationBar, with a red or green background color.
Regarding the other ways I found, it is pretty much a foreach loop of the views in the navigation bar, and if the view's kind of class is a button item then change the tintColor. It doesn't crash but it applies to all the UIBarButtonItem of my navigation bar (and I just want a specific button, the right one, not all of them). For example this tutorial is half working, my app crashes when coming back to the root view controller.
Digging into the subviews of the navigationcontroller.navigation bar wont fly with Apple, ...
the correct way to change the color of a UIBarButtonItem is to use a customView with the buttonitem. here is a link that explains...
UIBarButtonItem with color?
You simply create a segmented control with just one segment. Set its tint color as you like. You may also want to set its mode to momentary so it optically behaves like a button. Add the segmented control to the bar button item by using the initWithCustomView: initializer. That's how you typically create custom tinted buttons.
Example:
UISegmentedControl *cartControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10,7,60,30)];
[cartControl setTintColor:[UIColor colorWithRed:0.35 green:0.47 blue:0.65 alpha:1]];
[cartControl addTarget:self action:#selector(cart:) forControlEvents:UIControlEventValueChanged];
[cartControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[cartControl insertSegmentWithImage:[UIImage imageNamed:#"shopping_cart_white_small.png"] atIndex:0 animated:NO];
[cartControl setMomentary:YES];
UIBarButtonItem *cartButton = [[UIBarButtonItem alloc] initWithCustomView:cartControl];
[cartControl release];
[[self navigationItem] setRightBarButtonItem:cartButton];
[cartButton release];

What happens when back button is pressed in navigationBar

I wonder what is the function is called when the back button is pressed on the navigationBar.
I want to add some functionality when the button is pressed, who knows it?
Thanks in advance
The functionality you want is in the UINavigationBarDelegate protocol. Implement the -navigationBar:shouldPopItem: method and set your class as the delegate of the navigation bar in question.
Assuming you're referring to native controls, there's no way to do quite what you want, just using the built-in stuff. What you want to do is create a 'fake' back button, and stick it up in the left side of the navigation bar. Then you can set its target and action to whatever you like.
I suppose you're talking about the back button that automatically is added to a UINavigationBar when you push a new viewcontroller on a navigationcontroller.
The default action for the back button is to pop the current viewcontroller from the navigation stack and return to the previous viewcontroller.
If you want to define a custom behaviour to the backbutton you'll have to create a new button and tie a selector to it's action property:
//Create a new barbutton with an action
UIBarButtonItem *barbutton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleDone target:self action:#selector(doSomething)];
// and put the button in the nav bar
self.navigationItem.leftBarButtonItem = barbutton;
[barbutton release];
Edit:
//An example on how the doSomething method could be implemented.
-(void) doSomething
{
//Do your custom behaviour here..
//Go back to the previous viewcontroller
[self.navigationController popViewControllerAnimated:YES];
}