I have an UINavigationController and the first view is an UIView. I've setup two buttons and each one pushes another view , both UITableViewControllers.
The first buttons works just fine. The problem is: when I'm in the second TableViewController and I tap on the back button it tries to push the view again and only the second time it goes back to the Main View.
I also have an UITabBarController setup and I noticed that if I am in my first tab(the Main View with the two buttons pushing the two tableviews and precisely in the second view ) and i tap on another tab then tap back on the first - it shows me the content of my first UITableViewController and when I tap back it shows the second UITableViewController(that is supposed to be displayed) and only the second time i tap it goes to the Main View.
I don't know if it's understandable what I just said, here is also the code for the back button and the action for it:
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *back= [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backImage = [[UIImage imageNamed:#"backb.png"]
stretchableImageWithLeftCapWidth:10 topCapHeight:10];
[back setBackgroundImage:backImage forState:UIControlStateNormal];
[back addTarget:self action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
back.frame = CGRectMake(0, 0, 37, 26);
UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc]
initWithCustomView:back] autorelease];
self.navigationItem.leftBarButtonItem = cancelButton;
}
-(IBAction)cancel:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
The back button in the first UITableViewController is setup the same and works just fine...what could be the problem?
I've just added another UITableViewController and obviously now when I'm in the third view and I try to go back to the Main View it loads the view two times and the first UITableViewController before it goes back...
There are chances that you have pushed the second view controller twice. While you push multiple instances of view controllers at the same time, you won't see any difference in the pushing animation. It'd look like only one controller is being pushed. This is because you push the next view controller before the previous view controller was pushed completely.
Check your code if you are pushing the second view controller twice.
Related
I'm using this code in all ViewControllers to create back button:
self.btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
[self.btnBack setBackgroundImage:[UIImage imageNamed:#"back.png"] forState:UIControlStateNormal];
[self.btnBack addTarget:self action:#selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
-(void)cancel:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
But when I go to controller with UIWebView I need top tap 2 times to go back in ios 6.
And in ios 7 when I tap 1 time UIWebView disappeared show black screen with my navigation and on 2nd tap app crashes.
In all screen this works great maybe something special with UIWebView, I dont know.
Help please!
I push webview:
-(IBAction)doPrivacy:(id)sender
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
WebPageViewController *web = (WebPageViewController*)[storyBoard instantiateViewControllerWithIdentifier:#"WebPage"];
web.hidesBottomBarWhenPushed = YES;
web.urlToOpen = #"http://dfdfdf.co";
[self.navigationController pushViewController:web animated:YES];
}
I'm calling the same segue twice, you can fix this by unlinking the connection from the CELL DIRECTLY, to your segue, and having the segue connection originate at the top of the table hierarchy in IB, rather than nested inside the cell. Connect the segue from you View Controller itself, to the segue. If you have done this correct, when you select the segue, it should highlight the ENTIRE view it is coming from, not just the cell.
I have created a utility app that links by button to another xib called scene - I am trying to create a navigation control for that link. When the button is clicked to then have a 'back' button on my scene xib. I don't wish to have a navigation bar visible on the Main View Controller or the Flipside View Controller. I'm quite new to iOS and I have no idea how to do this?
Would it maybe just be better to have a button going back to menu on a custom HUD? I don't know if that can be done?
Thank you for any help in advance, and thank you for your time
you could create a custom UINavigationBar on your scene xib, and add the custom back button to it if you don't want to create NavigationController , alternate would be that you could just make your first view as NavigationController and push the Scene view over it and it will brings the back button on the child view which is scene, keep your navigationBar hidden when you are on MainViewController and show only on scene view.
For hide UINavigationBar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
And Your can crate Custom UIButton and put anywhere (As Your requirement).
and in its method, Write code for go back to UIViewController (previous UIVieController).
Such like,
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack addTarget:self action:#selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
btnBack.frame = CGRectMake(10, 10.5, 36, 39); // change it , As your wish
[btnBack setBackgroundImage:[UIImage imageNamed:#"MMBack.png"] forState:UIControlStateNormal];
[self.view addSubview:btnBack];
// call method of UIButton
-(void)goBack:(UIButton *) Sender
{
[self.navigationController popViewControllerAnimated:YES];
}
I have a UINavigationController and I have to keep the the default back button "the back arrow style" I just want to ask if I can change the back button action without build new one and change its style
AFAIK you cannot change the action of the default back button itself but you can place a UIBarButtonItem as leftBarButtonItem there and assign your own action.
If there is a leftBarButtonItem defined then this is shown and not the default back button.
However, keep the GUI guidelines in mind when doing tricks like this.
No. If you want a custom back button, you have to create a custom UIBarButtonItem, then assign it to the appropriate property:
self.navigationItem.backBarButtonItem = myCustomBackItem;
The back button in UINavigationBar is generated automatically as soon as u Push a new UIView. In order for you to customize the Back button is to Create a new UIToolBar + a UIBarButtonItem with custom view.
Code below is the sample to use a custom UIBarButtonItem in UIToolBar.
// create button
UIButton* backButton = [UIButton buttonWithType:101]; // left-pointing shape!
[backButton addTarget:self action:#selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:#"Back" forState:UIControlStateNormal];
// create button item -- possible because UIButton subclasses UIView!
UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
// add to toolbar, or to a navbar (you should only have one of these!)
[toolbar setItems:[NSArray arrayWithObject:backItem]];
navItem.leftBarButtonItem = backItem;
Link below is the design of iOS buttons in PSD format for further modifications.
http://www.chrisandtennille.com/pictures/backbutton.psd
You can make custom button and can make action on it but you can not change default backButton action.....
self.navigationItem.leftBarButtonItem = getBackBtn;
The UINavigationController sends a message to it's delegate when it pushes and pops a ViewController.
You can find out when the back button gets pressed by implementing the following and adding <UINavigationControllerDelegate> in your .h file
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.delegate = self;
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
self.navigationController.delegate = nil;
}
-(void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated{
//Test here if the View Controller being shown next is right below the current
// ViewController in the navigation stack
//
//Test by:
// 1. comparing classes, or
// 2. checking for a unique tag that you previously assigned, or
// 3. comparing against the [navigationController viewControllers][n-2]
// where n is the number of items in the array
if ([viewController isKindOfClass:NSClassFromString(#"ViewControllerClassThatGetsPushedOnBACK")){
//back button has been pressed
}
if (viewController.tag == myUniqueTagIdentifier){
//back button has been pressed
}
if ([navigationController.viewControllers[navigationController.viewControllers.count-2]==viewController]){
//back button has been pressed
}
}
Apple Docs UINavigationController Class Reference:
The root view controller is at index 0 in the array, the back view
controller is at index n-2, and the top controller is at index n-1,
where n is the number of items in the array.
I currently have a window with a view attached that has three UIButtons. When the user presses a button, I would like the view to change to a new view using a NavigationController.
So right now I have the about button coded like so:
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
aboutButton.frame = CGRectMake(236, 240, 60, 60);
[aboutButton setImage:[UIImage imageNamed:#"About.png"]
forState:UIControlStateNormal];
[aboutButton addTarget:self action:#selector (aboutButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:aboutButton];
And for the action function:
-(void)aboutButtonPressed {
UINavigationController *aboutView =[[UINavigationControlleralloc] initWithNibName:#"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[self.view addSubview:aboutView.view];
[aboutView release];
}
The About.xib file currently has nothing in it.
Now on to the problem... When the button is pressed a top navigation bar appears at the top but not in the animated sense like I have it coded. It just pops up. Also there is no back button to return to the view with the buttons on them. What am I doing wrong? I can provide more code or details if this is not clear enough.
Edit: Here is a picture to better understand what is happening.
After clicking the about button:
http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-09%20at%2011.28.40%20AM.png
Edit 2: Removed some wonky code for a back button that shouldn't of been there.
Most of the code after pushViewController looks dodgy.
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController **alloc**] initWithNibName:#"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
That should at least push your empty view onto the stack and give you a back button automatically.
In the iPhone maps app there's a toolbar at the bottom of the map view (it contains the Search/Directions segment control and others). When moving from the map view by clicking on a callout, the toolbar slides out with the map view, leaving the next view (a table controller) with no toolbar.
I've tried to do the same thing with [self.navigationController setToolbarHidden:YES animated:YES] in the second view controller, but this gives a strange toolbar sliding down animation, while the map view is sliding to the left.
Using [self.navigationController setToolbarHidden:YES] in viewDidLoad also causes a bad effect (it makes the toolbar disappear the moment the push animation starts, leaving an ugly white space).
I'm assuming the answer to this is to use a nib file, but I'd prefer to do it programatically (if possible).
How can I get the toolbar to "stick" to the map view and slide out with it when I push a new view controller? Thanks.
Gourmet Haus Staudt http://img.skitch.com/20100518-xfubyriig48d3ckaemjg2ay8q.jpg
It turns out the answer is to create the toolbar directly and add it to the view yourself. This is in the code for a UIViewController with a UINavigationController. The frame coordinates can change according to what is on screen.
- (void)viewDidLoad
{
// Add a toolbar to the view
CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"compass.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(zoomToCurrentLocation)];
compassButton.width = 30.0f; // make the button a square shape
[myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
[compassButton release];
[self.view addSubview:myToolbar];
[super viewDidLoad];
}
I was around this for a day once. Really dont get the programatically answer, but the best way to views to behave correctly, is to do the interface in the interface builder. If you set items for a toolbar in your code like:
[self.navigationController setToolbarItems: control1, control2,..., nil] animated: NO];
with my little experience, I can say that you are saying to the entire application to have a toolbar present when you push new views unless you hide it (or you are using a tabBar), but hiding it you get those unwanted effects.
You can try this:
[self.navigationController setToolbarHidden:YES animated:YES];
in your first controller - (void)viewWillDisappear:(BOOL)animated method,
and setting hidden to NO in - (void)viewWillAppear:(BOOL)animated method in the first controller too.
Hope this helps.
PS: And if you get the programatically answer, let me know! =P
Override the second view controller's -viewWillAppear: method to hide the toolbar.