didSelectViewController not being called when switching tabs manually - iphone

I have a tab bar interface with three tabs. I would like them to animate when I switch between them. I implemented didSelectViewController (and all the associated delegate stuff) which is called when I press the tabs but not when I switch tabs programmatically. The docs say as much,
"In iOS v3.0 and later, the tab bar controller calls this method regardless of whether the selected view controller changed. In addition, it is called only in response to user taps in the tab bar and is not called when your code changes the tab bar contents programmatically."
Anyone know any workarounds?
Thanks! - Jon

Well, if you are switching them programmatically why can't you create proper animation yourself? I mean you do know which tab gets selected, right?

you can call the method when you switch them programmatically yourself. or write another method to do your animation and call IT whenever you switch tabs programatically

Related

Making a UITabView show the second level of a navigation controller by default

(Apologies for not being able to embed my images yet).
Using iOS storyboards, I have a UITabBarController with a UINavigation Controller/UITableView(1) embedded in it. This UITableView(1) then calls another UITableView(2):
What I'm trying to do is to make UITableView(2) appear when the Tab Bar is changed to that tab, and then have the UINavigationBar left arrow button exist to get back to UITableView(1).
The existing functionality I can think of which does this is the iPhone Mail app, where when you launch it you see your Inbox, and you can hit the left-arrow Mailboxes button to get back to your mail box list.
I've tried attaching the tab bar directly to UITableView(2) but it doesn't work as expected, there's no left arrow back button to get back to the previous view when the app is run.
I've also tried adding a navigation controller to that UITableView(2) and the Navigation controller correctly appears, but still without any back button:
Any suggestions as to what I'm doing wrong would be greatly appreciated, I'm fairly new with storyboards and it's difficult to find what to search to get this working.
If it's not possible with just storyboards themselves, is there some kind of automatic (non-visible) push to the 2nd UITableView I could do?
Thanks!
Nick.
This tutorial will definitely help you : http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and-tabbar-controller-part1/
I ended up implementing it the following way, as I wanted to perform the majority of the work within storyboards.
I set up the storyboard with the tab bar embedding the UINavigationController, which contained UITableView(1) which then contained a custom segue to UITableView(2):
Then within the class associated with UITableView(1) I added this single line:
- (void)viewDidLoad {
[self performSegueWithIdentifier:#"campaigns" sender:self];
...
}
On load of the tab, the viewDidLoad of UITableView(1) instantly calls UITableView(2) without any kind of animation, showing the back button to UITableView(1), which is exactly what I wanted.
Thanks to those who responded!
You can implement the delegate method as below.
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
In this method you can check for the tabBarController.selectedIndex or viewController object. This ensures the selection of correct tab , then push the controller having table 1, then push the controller having table 2.

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.

How to make a tabbar such that the first tab of the tabbar should not remain selected

I have created a Windows application.in my appdelegate I have called a controller class named analogcontroller and added this class to my window so that when I run my application the page that should come first is this page that contains an analog clock with five tabbaritems in it each calling different class.
So in the analog controller class xib I have added a tabbar with 5 tabbaritems in it. But when I run my application the page that gets opened is the page of the firsttabbaritem instead of analogcontroller. I want that when I run my application my xib of analog controller should be called with 5 tabbar items below it and when I click on particular tabbaritem then only its corresponding page should be opened, otherwise not. How is this possible?
you can set tabbar selected index to your desired tab index it starts from 0
you can write something like tabbarcontroller.tabbar.selectedindex =1;
Forgive syntax errors... you should try this. xCode is rich editor.
If you have a visible tabBarController, then something will necessarily be selected. No way around this.
However, if you would like to hide the tabBar, then you can certainly do that, either by setting its hidden property to YES or by presenting a modal view on top of the selected tab (e.g. the first viewController).
similar question here

What to do about "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted."

I'm writing an iPhone app using Appcelerator Titanium Mobile. I am hiding and showing the tab group based on what window has focus.
dashWin.addEventListener("focus",function(e) {
if (dashWin.tabGroupVisible == true) {
dashWin.tabGroupVisible=false;
tabGroup.animate({bottom:-50,duration:500});
}
});
The code above hides the tab group when dashWin receives a focus event. However, I see this message in the Titanium console when the event fires while running in the iPhone simulator:
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
A Google search turns up one result: Another StackOverflow question that may have a hint as to what's going on.
I got this error when I linked Action Segue or Selection Segue from one view to another view through storyboard and performed the same segue programmatically again, which makes the navigation controller perform the same segue twice.
2 solutions for this case:
Removing the code that pushes the view. Just let storyboard perform the segue for you. This is good for most situations.
Replacing Action Segue or Selection Segue with Manual Section and do - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender by yourself. You may find this solution useful when you want to customize the behavior of segue according to the sender.
Usually a tab group acts as the root of your app's navigation. When a user taps a tab, that tab's window is focused.
Next, when a user triggers an action that requires a new window appear, it usually appears either modally or on top (in the navigation stack sense) of the current window. In the latter case, tell the current tab to open the new window.
If you set the tabBarHidden property to false (when you create the new window), the tab bar will be hidden for you when the new window is opened by the current tab.
Will this more standard approach work for you?
I had segues that were leading back to my main navigation controller which was causing this. I fixed the problem by setting the main navigation controller back to the top of the stack. Here is the code:
- (void) viewDidAppear:(BOOL)animated
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
Recently, I've faced the same problem. The reason was:
-I was trying to pop view controller twice by mistake.
you can check this crash by setting breakpoints on push and pop View controllers

iphone persistent button on all views

I have a navigation app that has many screens the user navigates to. A handful of views manages these screens dynamically. What I want to try to do is add a button that will always show up on every screen the user views. I need to do this so that the user is always able to preform the action associated with the button regardless of where they are in the app.
Is it possible to achieve this by adding this button only once and having it passed between views like my navigation bar is? Or do I just have to man up and add this button and its functionality to every single view file I have?
Thanks
I would say it probably depends on what the button does. If the button is generic to all views, meaning it affects all views the same exact way so no customization for a given view is needed, then a way to do this would be to include the function in the App Delegate or as a subclass to your Navigation controller.
You can then use the rightBarButtonItem to always show the same button and just access that method. You would just have to add code for the rightBarButtonItem in each viewDidLoad (but they'd all be the same).
I did something similar to this with an "Upgrade" button on one project. Since all the button does is launch the AppStore to the paid version, it's independent of all views and I can place it anywhere.
You can put the button on the navigation bar if you want. Alternately, the more generic way to do this would be to split your single view into two views. One is small and only contains your button but always stays on the screen. The second is your workspace and you swap in and out the views that are displaying the current content. You'll note that this is the way the navigation controls and tab-bar controls work.
The last way to do this would be to put different buttons, in the same place, on each view and have them all trigger the same action. As far as the user is concerned this looks like the same button. Disadvantage here is that you can't alter the button across all views in a simple manner.