Can't hide back button inside my navigationbar - objective-c

I am trying to hide my backbutton in the firstView after I logged into the application. I have this piece of code inside my ViewWillAppear.
self.navigationController.navigationItem.hidesBackButton = YES;
self.navigationController.navigationBar.hidden = NO;
But my back button will not dissapear.
any help ?
Kind regards.

use this instead
self.navigationItem.hidesBackButton = YES;

Try these couple of lines , this will work out:
self.navigationItem.hidesBackButton = TRUE;
self.navigationItem.leftBarButtonItem = nil;

You can set a custom UIBarButtonItem as left bar button. That one you can try to hide or desing in a smooth way that it helps achieving what you want to do.

If you want to hide back button, than maybe you do not want to get back to previous screen. If this is the case, instead of pushing navigation controller show your view modally.
Otherwise do the following:
UIButton* myButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
UIBarButtonItem* myBarButton=[[UIBarButtonItem alloc] initWithCustomView:myButton];
myButton.hidden = YES;

Related

how to change the UIBarButtonItem button design?

I am newbie for iPhone application.
What I have is as below.
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.leftBarButtonItem = flipButton;
[flipButton release];
BUT, problem is button design. It is just square button.
How can I make this button to same as Back button?
Any idea/ suggestion would be appreciated.
I was trying with
self.navigationItem.leftBarButtonItem.title = #"Back";
self.navigationController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(goBackToSAMA:)] autorelease];
but its working working. Not working means, goBackToSAMA is not getting invoked and button text is also not coming to Back.
One possiblity might be to change the back bar button via this method:
backButtonBackgroundImageForState: barMetrics:
Another possibility might be to replace the "backBarButtonItem" with a custom view.
If you want to roll your own custom bar button item, the option you're looking for is the "UIBarButtonItem" method "initWithCustomView", and that's where you can put in designs of your choosing.
As far as I know, ther is only one way how to display the standard back button. You have to push UINavigationItem in UINavigationBar. Or better: there need to be navigation item to be popped.
IMPORTANT: This will not work nice with UINavigationController's bar, so use your own!
UINavigationItem *firstItem = [[UINavigationItem alloc] initWithTitle:#"Go Back"];
UINavigationItem *secondItem = [[UINavigationItem alloc] initWithTitle:#"Something"];
navigationBar.items = #[ firstItem, secondItem ];
This code will display “Something” as a title and to the left, there will be back button saying “Go Back”. By default it shows the title of previous item, but you can customize it:
firstItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Another Title"
style:UIBarButtonItemStyleBordered
target:nil
selector:nil];
Note that the target and selector are nil. You can not customize the action of back button like this, because it is special. You will need to implement protocol UINavigationBarDelegate and this method:
– (BOOL)navigationBar:(UINavigationBar *)bar shouldPopItem:(UINavigationItem *)item {
[self doYourActionHere];
return NO; // Returning YES, would trigger pop animation.
}
Or just use custom background image…

How to set UIBarButtonItem with customView without losing selector

I have a UIBarButtonItem in IB
That button has selectors.
Things work fine but I want to change the appearance.
Hence I did:
UIImage * imageSetting= [UIImage imageNamed:#"setting-button"];
UIImageView * imageView = [[UIImageView alloc]initWithImage:imageSetting];
self.editSettings = [self.editSettings initWithCustomView:imageView];
Now appearance works fine but pressing the button won't get me to any code at all.
What to do?
Replace
self.editSettings = [self.editSettings initWithCustomView:imageView];
with
[self.editSettings setCustomView:imageView];
Hope this helps you..
After you instantiate your custom item, you need to set a target and an action on it.
e.g.
if(self.editSettings) // make sure it exists
{
self.editSettings.target = self;
self.editSettings.action = #selector(doSomething:)
}
(assuming you have a method named "doSomething:" in your view controller...
You can have a create action method for that bar button item and then connect that action in xib you can do this programmatically also using below code:
self.navigationController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:#selector(addtechniciansnametoplist:)];

Adding two right bar button items to the navigation bar

I have a navigation bar to which I have added right BarButton successfully. Both the NavigationBar and BarButton are created programmatically. Now according to my requirement I got to add two right BarButtons to my navigation Bar. Can anyone tell me how to do this? My app is targeting ios4.
This code will do the trick for you,
NSArray *barButtonItems= [[NSArray alloc] initWithObjects:self.addButton,self.sortbyButton,nil];
self.navigationItem.rightBarButtonItems=barButtonItems;
where addButton and sortbyButton are 2 separate BarButton Items
I know it is too late but I faced it recently. So here is what I did
Create a UIView in code and add the buttons as subviews into this view.
Create a ToolbarButton using [[UIBarButtonItem alloc] initWithCustomView:buttons]
Assign this toolbar button as the Left or right barbuttonItem as U wish.
If you application is targeting iOS 4 and above then you should take UISegmentControl and have two segments on it. Catch value changed action event and check which segment is selected and do you operation accordingly.
You can also set images to segments to make look and feel better.
As the documentation to UINavigationItem1 describes, it has a property rightBarButtonItems (as well as leftBarButtonItems) where you can give an array of UIBarButtons. They are display from right (index 0) to left (index n-1).
#Matthias, As stated in documentation, rightBarButtonItems property is available from iOS 5 and above and this function needs to be supported also on iOS 4.
So, UISegmentControl is best way to achieve this.
NSArray *segmentTextContent = [NSArray arrayWithObjects:
NSLocalizedString(#\"Group By\", #\"\"),
NSLocalizedString(#\"Filter By\", #\"\"),
nil];
UISegmentedcontrol *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 125, 30);
[segmentedControl addTarget:self action:#selector(toggleUnit) forControlEvents:UIControlEventValueChanged];
segmentedControl.tintColor = [UIColor lightGrayColor];
defaultTintColor = [segmentedControl.tintColor retain];
self.navigationItem.rightBarButtonItem = segmentedControl;
[segmentedControl release];

Removing UIPopOver permittedArrowDirections

I have a UIPopOverController and this is my code:
[myPopOver presentPopoverFromRect:CGRectMake(20,5, 325, 600) inView:self.view permittedArrowDirections:**UIPopoverArrowDirectionLeft** animated:YES];
However I need no direction arrows.can any one tell me how can I do it. How can I remove the arrow from it?
Now myPopOver displaying 4 photolibrary images on a Row.can any one tell me how can arrange or display only two images on a row in myPopOver controller.
And also it dismissing when I click on ay place.I don't want to dismiss it.is the any property to avoid the dismiss of uipopover?
I used the code
imagePopOver = [[UIPopoverController alloc] initWithContentViewController:self.plc.imagePickerController];
imagePopOver.popoverContentSize = CGSizeMake(150,300);
You can remove arrow from UIPopover with the help of below code.
[popOverController presentPopoverFromRect:CGRectMake(200, 300, 335, 332) inView:self.view permittedArrowDirections:NO animated:YES];
in swift
let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .ActionSheet)
alertController.popoverPresentationController?.permittedArrowDirections = []
You cannot have no direction arrows with a UIPopover. If you just want a view that appears than you will need to make your own custom UIView and hide it or turn the alpha to 0 and fade it in when you need it. As far as view layout goes you can set the frame property of your image views that you are showing to control where they are placed.
My solution in SWIFT:
popover!.permittedArrowDirections = nil

Start animating a UIProgressView with a tag?

downPreView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
downPreView.tag = indexPath;
downPreView.frame = CGRectMake(75,28, 215,60);
downPreView.progress = 0.0;
[cell.contentView addSubview:downPreView];
Now how do I start animating downPreView with a tag of 2, etc?
Thanks!
You can grab a view with the viewWithTag method. Like [cell.contentView viewWithTag:1]
Update
First of all. You cant animate a progressView, you can show it, hide it, and you can edit it's progress level. If you want to edit it's progress, you have to set it like [downPreView setProgress:0.1]. If it's set to 1 the progrees indicator will be at the end.
However if you want just a spinner, you can use UIActivityIndicatorView.
If you cant get the cell, then you can use it's parent view. Like [self.view viewWithTag:1]
After this you have to cast UIProgressView on it to avoid warnings.
UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:1];
progressView.progress = 0.1;
For more info about UIActivityIndicatorView please see the documentation.
You cannot access an object by it's tag, you have to retain the object if you want access. Say if you have an array of progress views... you can enumerate it and ask
if (object.tag == tagWanted) {
doSomething;
}