I have a storyboard enabled App with a TabBarController where I have added viewcontrollers through the interface builder.
Then I followed the iDevReceipes post to add a custom button in the center, which hide my third or center tab bar item with a custom button.
I'm not able to make the TabBarController select the middle tab when a user clicks the button. I wired the button with a selector and within the method I added a code which was supposedly a solution which worked for many on Stack Overflow i.e self.tabBarController.SelectedIndex = 2; this was called in viewWillAppear
This is somehow not working and selecting the correct tab. I had a NSLog inside the method of the button and I found out the button works but the tab is not getting selected.
The tabbarcontroller has a class with nothing inside this.
You have the right idea, but you need to use a setter method and not set the property directly; this is one instance where it does make a difference. Also, I may be misunderstanding you, but you need to call this code in the selector for the button, not in the viewWillAppear method. Here's the code you'll use to select the middle index.
[self.tabBarController setSelectedIndex:2];
Related
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.
I am showing a ExchangeWardrobe view.In this view i have a button Mywardrobe on click on this button,opens User’s own Exchange Wardrobe.This will have following 3 tabs..one is myProducts view..in which there is one button offer..click on this offer button open Product detail page..which is also in another tabbarcontroller..so I want to ask Is it possible that a class of one tabbarcontroller can call another class of another tabbarcontroller?
In your app delegate you can add and remove tab bar controllers from your main window (ie [window addSubview:usersWardrobeTabBarController.view]).
just create a method in your app delegate that swaps these views adds/removes them from your window. Or if memory isn't an issue then add them both and hide/unhide them.
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];
}
(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.
I have my main program with MainAppDelegate.h,MainAppDelegate.m.
I have created two custom navigation controllers ANavController, BNavController classes and have created added the controllers in Interface Builder and assigned my custom classes to the two controllers inside the MainWindow.xib
When the application first loads I make it render the first NavControllers and its view in the didFinishLaunchingWithOptions method:
[window addSubView:ANavController.view];
This is works fine and loads the first navigation controllers view. My problem is that within the view on each nav controller, inside the viewDidLoad method I have created a UIBarButtonItem which I add to the right side of the navcontroller.
I'm trying to make this button call an action method defined inside my MainAppDelegate.m.
For both of my two custom NavController classes I have set the delegate to MainAppDelegate inside interface builder. I try to define buttons like so:
[flipButton addTarget:self.delegate action:#selector(changeModeAction:)
forControlEvents:UIControlEventTouchUpInside];
and obviously then inside MainAppDelegate.m I have defined a method:
-(void)changeModeAction:(id)sender
This method should flip the ANavigationController currently in the window to he BNavigationController.
But it obviously crashes on the addTarget:self.delegate. What's the proper way to do this?
Basically I'm trying to add a button to the top right of each NavControl which will fire a FLIP page animation, switching to the other NavController and it's stack.
So if you're two levels deep on ANavController and you hit the top right button, it will flip to BNavController and wherever you were last in it's stack. Hitting the button again will flip the page again back to ANavController and you'll still be two levels deep, before you switched to B. Does this make sense?
I think my idea implementation needs some work?
Sorry for posting this as an answer instead of a comment - my reputation is too low to add comments - but could you please provide the error message?
EDIT: See thread below for details - the problem was that 'self' was not a subclass of UINavigationController and therefore did not have a delegate property. Changing this to self.navigationController.delegate worked.