I am building basic application. It uses the tab bar with 3 views. I have a button on the first view. When i click it, i want it to switch to like the 3rd view but keep the tab bar at the bottom. Right now, i have it working, but when it switches to the 3rd view, i lose the tab bar.
I am new so take it easy on me. I have tried searching in this site, but nothing helps entirely. If possible please provide the code and which files it should go into.
In my .h i put this code:
-(IBAction) btnClickedSell1:(id) sender;
In the .m i put this code:
-(IBAction) btnClickedSell1:(id) sender {
Selling *second = [[Selling alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
I believe i must have the right code however i'm not sure of which files they should go into exactly and the exact steps to take in IB.
Any help is greatly appreciated!
You should not use presentModalViewController:animated, if you just want to switch to the 3rd view I think you should try this code:
[yourTabBarController setSelectedIndex:2];
you can get yourTabBarController by NSApplicationDelegate if your app is based on TabBar application.
In tab based Application each bar button is act as like ViewController. So you can redirect into next ViewController You can't keep your first Bar button.
Related
I have an app (with a UITabBarController) that can reach the final payment view via two tabs, each with their own NavigationController.
(The illustration only shows the two tabs in question)
When payment is successful I want to reset both NavigationControllers and present tab 1.
If I was on tab 1 I could just use this code:
self.navigationController?.popToRootViewControllerAnimated(true)
But if I was on tab 2 that only brings me to the first viewController in navigationController in tab 2...
How can I present another tab while also resetting the NavigationController I am on (and others)?
Any help is very much appreciated. Thank you !
1) Create a custom UITabBarController or make a category that has a method called something like: completePayment()
- (void) completePayment
{
[self setSelectedIndex:n] // n is the index of your destination tab
[[[self viewControllers] objectAtIndex:m] popToRootViewControllerAnimated: YES]; // reset the stack in the current tab
}
2) trigger this method from the ViewController that the paymant is done as such:[self.tabbarController completePayment];
3) Profit!
There are probably ways of doing this in somewhat hacky ways, but what I will suggest you is that you reconsider your flow when you ask yourself a question like this one. Each UITab is designed to hold a UINavigationView that is self contained and independent from other UITab elements. If you force reset a tab that you are not on, you are breaking the flow and confusing the users.
So I recommend you push your Payment ViewController, wherever you need it in the app. And don't mess with other Tabs states.
I'm trying to get a storyboard to bring the user back to the first screen of a storyboard when a button is pressed.
I have the button click hooked up and the method is hit when it's tapped but it's either doing nothing or crashing the app depending on what I've got in that method (I've tried so many things at this stage that I can't remember the original setup)
The best I can achieve is that once tapped the user gets brought to the third screen in the storyboard, rather than the first.
Here's the storyboard, I want to get the user to move from the button circled in red back to the very first view controller (top left of screenshot).
Maybe the storyboard layout will help people, I'll post some of the various methods I've tried as well.
Here's the method
- (IBAction)done:(id)sender
{
//Multitude of attempts have been in here, either they don't do
//anything or they just send the user back to the NEW REPORT screen.
//Button does nothing in these following events
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
If you want to start fresh, have the button instantiate a new instance of the first controller, and set it as the window's root view controller:
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:#"First"];
self.view.window.rootViewController = first;
It's not clear to me exactly how you're getting to that controller with the button in question, but you might want to put dealloc methods in all your controllers with a log to see if all are getting deallocated at some point in your navigation, and when you go back to the new first controller as I've outlined above.
I don't know how to ask this more precisely. I have a master/detail and am creating the whole thing programmatically. I subclasses UISplitViewController and populated it with the two controllers, and everything looks as it should until I set splitViewController:shouldHideViewController:inOrientation such that it returns YES in portrait modes.
When I have the master hiding in portrait and portrait upside-down, as expected, it hides. However, I can't add a "Master" button to the nav bar at the top of the detail view in splitViewController:willHideViewController:withBarButtonItem:forPopoverController. This is probably because I have a fundamental misunderstanding of how I'm supposed to accomplish that task.
I followed the Apple examples and did:
barButtonItem.title = NSLocalizedString(#"Master", #"Master");
[detailController.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
I'm not getting any errors, but no button either. I speculate that perhaps it's because what I'm saving as detailController in my subclass is a UINavigationController and not a UIViewController.
Any guidance on this is much appreciated!
Having written this, I realized that there were several errors in wiring this whole thing up:
splitViewController:willHideViewController:withBarButtonItem:forPopoverController really wants you to not only to set the barButtonItem title, but also to add it to the nav bar of the detail controller.
If you ever want to programmatically dismiss the popover, you have to store the popover supplied in splitViewController:willHideViewController:withBarButtonItem:forPopoverController someplace in the master view.
So, the answer to the first part of the question was:
barButtonItem.title = NSLocalizedString(#"Master", #"Master");
[[detailController.topViewController navigationItem] setLeftBarButtonItem:barButtonItem animated:YES];
That got me to the UIViewController that can set a UIBarButtonItem on the navigation bar. I'm sure I could have done this directly on the UINavigationController but didn't immediately see how.
The second, unasked part of this question, deals with what to do with the popover once it's visible. Again, I needed the detail controller to know what the actual popover was so it can be dismissed, so in splitViewController:willHideViewController:withBarButtonItem:forPopoverController, I added code like:
[masterController.navigationItem topViewController].popoverController = pc;
where pc is the value of the argument passed into the delegate method. Then, in my master controller, I have a UITableView and on the didSelectRowAtIndexPath, I simply did this:
if(popoverController)
[popoverController dismissPopoverAnimated:YES];
And that's what I learned in iOS school today :)
I am trying to write an app that displays a simple logo/splash page while the app retrieves some data. I cannot seem to find a tutorial anywhere.
I have a "MainWindow.xib" file that will have my splash page, and I'm setting that as my "Main Interface" in my Info.plist, however, I cannot seem to see how to replace that page with a .xib that contains a UINavigationController. I thought I would just create a new UIController, that had a UINavigationController and in my .xib I'll drag in a Navigation Controller and set all my information, but it's giving me real fits.
So, I figured I would have a UIController that I would "alloc" and "init" with my second .xib that contains all my navigation.
myMainController = [[UIController alloc] initWithNibName:#"MainNavController":nil];
in "MainNavController.xib", I've dragged in a Navigation Controller, but I don't know what to connect it to????
I'm sure I'm going down the wrong, path; but I cannot find a decent tutorial for this.
Can someone give direction or link to a decent tutorial?
Thanks.
Are you ever actually adding the new controller to your existing view? If not, something like:
[self.view addSubview:myMainController.view];
should do it for you. A better alternative is likely to be:
self.window.rootViewController = myMainController;
But I'm fairly new to this and maybe I've missed something ...
To display a splash screen while the app is loading you can use Default.png image file.
However, I think your question is how to display another splash screen for a period of time after the app has been loaded.
In you MainWindow.xib keep your window separated from your Navigation Controller. Add your splash screen view with an image to the xib.
Make two outlets: one for slash view, one for Navigation Controller.
IBOutlet UIView* _spashScreenView;
IBOutlet UINavigationController* _navigationController;
In applicationDidFinishLaunching method add your splash screen view to the window.
[_window addSubview:_spashScreenView];
// lay it out
When you are ready to display your navigation controller:
[_spashScreenView removeFromSuperView];
[_window addSubview:_navigationController];
This may be an easy answer for someone.
I first built an a navigation app that had a table loaded from SQLite. The rootViewController (UITableViewController) is loaded from the mainWindow.xib . I added the search and scope functions, and push a detailed view (UIViewController) from a row selection just fine, and can navigate back and forth to and from the table and filtered results, search, with scoping different searches. All is good, no errors, crashes, or warnings.
Now I have tried to add a tabBar interface on top of the rootViewController...after 2 days I have got the TabBarController to display (I was trying to implement it directly on the RootviewController, but found I had to implement it in the mainWindow) and I can select different views (xib) from the tab bar. I have one tab that has no view assigned to it in IB, and I can see the RootViewController load as it did before as the first screen in this tab view, even though RootViewController is not assigned in the tab.
The problem is I cannot click on a row in the table when it loads this way. Alternatively if I create a tab, calling the RootViewController, I get the search bar on the top, but the table is empty. I feel this is somehow due to my appDelegate loading the rootViewController, and me not knowing how to get it to "load" or "reload" into the tab, or something like this. I tried creating a separate "search.xib" that was identical to the original mainWindow before adding the tab bar, then trying to load that in the TabItem, so it called the appDelegate first, but no cigar: crash. I verified the search.xib works fine, as I put it as the info.plist "Main nib file base name", and this loads fine and works as before this BS of adding a tabBarController...
I would start pasting code, but not sure what someone would need to know what is missing or wrong. I do call [self.tableView reloadData] in -(void)viewDidLoad, in RootViewController.m but it is not helping this problem at all.
Can anyone help?
Mac OS X is version 10.5.8, and I am using XCode 3.1.4.
// Create and configure the main view controller.
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
rootViewController.violinMakers = violinMakers;
[violinMakers release];
// Add create and configure the navigation controller.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navController = navigationController;
[navigationController release];
// Configure and show the window, Override point for customization after app launch
[window addSubview:[navController view]];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
Thanks for trying to help!
The last section above appears to be where I should get the RootViewController to be on top of the stack, but not sure how.
// <AppName>AppDelegate.h
#interface <AppName>AppDelegate: NSObject <UIApplicationDelegate,
UITabBarControllerDelegate, UINavigationControllerDelegate>{
UIWindow *window;
UINavigationController *navController;
UITabBarController *tabBarController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navController;
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
#end
Ben - I do realize what you are saying about the rootViewController being behind the tabBarController. I just don't know how to set the tabBar as the main view, and the navController as a tab of it. I will look at the tutorial you mention and see if that helps explain it. Thanks Ben!
09-10-14 update
Some progress!
I now have the view in the tab with the with the NavBar at the top. I know it is coming from the correct .xib file as the title and the search can now be clicked on, and the scope buttons are the correct names. .... but as before, if I got to this stage or even close, the table information is not loaded into this tab(all cells are blank). How do I get my table to load properly in this cell? I know it is loading on launch, as if there is no view assigned at all to this window, I can see the table n Nav, but cannot click on it.(So close, yet so far away). I now have the tab set up correctly, but the table is not loading properly... rrrr
I have the typical
[self.tableView reloadData];
in the viewController.m in the method:
- (void)viewWillAppear:(BOOL)animated
and in
- (void)viewDidAppear:(BOOL)animated
and in
- (void)viewDidLoad
and tried it some other methods as well, but it is not reloading the table info when I select the tab.
Any ideas on how to reload this table in the TabBar view properly ?
I did find a good tutorial on tabBars that went a bit further than some others in explaining with IB. Twillo Embed Nav in a Tab Tutorial
It would appear that you're adding your tab bar controller on TOP of your table controller. It's not clear where you set up tabBarController, but you should only be adding ONE view to your window (in the third-to-last and second-to-last lines you are adding two).
The basic premise for Navigation and TabBar controllers is that your Tab Bar controller is the primary, and you'll add the Navigation controller as one of its tabs. Then, add the tabBarController.view to your window. Which ever tab is selected will be the visible one.
There's a tutorial posted on the web on this subject.
Basically here is what I have found for those of you with the same problem.
It is not easy, or really suggested by Apple it instantiate a tab bar later in a program. Yes it can be done, but now I would suggest a different method. I found a modal view controller works just a good as a tabBar, abeit smaller, but takes less real-estate, because it can be placed in the navigation bar. If you are planning an app with tabs, start with a tab based app and then customize it, don't try to change the navigation structure later, which is the underlying issue. Secondly I have found Apple's documentation on Interface Builder less than satisfactory. Everyone seams confused and it's implementation limits the actual final product cusomization, not making it easier. Not to mention more confusing on "wiring" all the elements together in it. That really sucks, and I took 2 weeks in trying various methods to make it work. It is not impossible, just incredibly unintuitive, and a mistake on my part to change paddles half way down stream. Look at the alternatives to the way you want to give access to the information, and I think you will find better ways like the modal view to accomplish this, or by simple buttons with IB actions to access different views or further information.
Happy Programming!
Kirk