Wow, awesome link. I'm finding their example projects the most useful code examples I've found yet. Thanks a million for that link, It just shaved a day or dozen off my UI making learning curve.
Yay!
Quote:
As feedback to the whole (to IB or not to IB) debate, the stanford class examples I've gone through so far make very little us of IB in favor of manually declaring their views and controllers in the application delegate.
YES. In fact, at one point in the lecture videos, I think someone asks the instructors "to IB or not to IB" and they do in fact recommend it, but for very basic UIs, it can EASILY be overkill. When you start to position things and wire stuff up and get more detailed, IB becomes a big help since it follows the HIG for things like spacing, placement, etc.
Very glad to hear the cookbook is matching your style! Everyone's different, so you have to go with what works. It really is a terrific book.
This is exactly what I am trying to do. My table nav loads in a tab bar with 5 tabs linked to 5 nibs but I cannot figure out how to populate those nibs/tabs with the data for the row selected. The title for the tabs comes over from the table with tabViewController.title = ... indexPath.row] valueForKey... etc
Any luck, anyone, with table to tab?
ps Let me know of you want the code to go from table to tabs (but it won't know where you came from - except the title!)...
Ha! Interesting. So you're in a Nav controller, but you want the Tab Bar to show up after the fact, not before.
It's interesting that you mention this because some folks, when starting out to go the usual direction (tab bar controller, then a nav or view controller in each tab bar item), sometimes end up with what you're looking for ... by mistake!
I've never set out to do this, so I'm going to wing it here a bit. Bear with me ...
So ... what if we set up a new view controller (that you'd push onto the nav controller stack), and that controlled a view that contained a tab bar controller? So far, so good.
Then, for each of those tabs, you would likely not add nav controllers, but just basic view controllers (so that the nav at the top stays put and doesn't change). Each of those VC's views should have autoresizingMask set such that they resize gracefully. (You have the nav bar at the top, so the size isn't full-height anymore, else you hide the nav bar, "... and that would make folks sad.")
You probably don't need to worry about hidesBottomBarWhenPushed on the view controller, since you don't want to hide it before a new VC appears, you want to show it as part of the new VC appearing.
I hope this helps draw a bead on things! Keep us posted.
That is exactly what I am looking for. I am essentially on that path, just not there yet. (I had to stop working on that project while I fixed an Apple rejection...lol)
I hear your concept and it sounds very promising, now I just need to sit down and try to figure out the code.
I'll start now...Ha
PS. I really do believe that it WOULD make folks sad....lmao!!!
I am looking for kinda the same thing so did you anyone ever get this sorted?
Thanks :-)
Quote:
Originally Posted by hm50
That is exactly what I am looking for. I am essentially on that path, just not there yet. (I had to stop working on that project while I fixed an Apple rejection...lol)
I hear your concept and it sounds very promising, now I just need to sit down and try to figure out the code.
I'll start now...Ha
PS. I really do believe that it WOULD make folks sad....lmao!!!
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
MyTableViewController *myTableViewController;
MySecondTableViewController *mySecondTableViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) MyTableViewController *myTableViewController;
@property (nonatomic, retain) MySecondTableViewController *mySecondTableViewController;
@end
@implementation AppDelegate
@synthesize window, myTableViewController, mySecondTableViewController, tabBarController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init]; // creates your tab bar so you can add everything else to it
myTableViewController = [[MyTableViewController alloc] init]; // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
[myTableViewController release]; // creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
mySecondTableViewController = [[MySecondTableViewController alloc] init];
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
[mySecondTableViewController release]; // does exactly the same as the first round, but for your second tab at the bottom of the bar.
tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; add both of your navigation controllers to the tab bar. You can put as many controllers on as you like, but they will turn into the more button like in the iPod program.
[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window
[window makeKeyAndVisible]; // makes the window visible
}
- (void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
} // lets go of everything else, thats so your program doesn't create any leaks of memory.
@end
I just typed up this quick App Delegate to show you how to do it. Yes, you do have rights to use whatever part of it you wish, and yes, you can ask any questions you like.
Please do note:
a ) I release the table views because they have been retained by the Navigation Controllers. Thus, I have doubled up and am taking double the memory. Once you have a nav controller holding your view, drop it. This saves memory. These nav controllers are set to drop automattically with their autorelease so there is no leak issue.
b ) if you need to add only one item to your tabBar for some strange reason, or just to test, change "arrayWithObjects: blah, blah2, nil" to "arrayWithObject: blah" and drop the nil.
Does this help you???
Hi DevTeamOfOne,
I am new to iPhone development. This thread really help me to create tabBarController and NavigationController in it. Is it possible to change tabBarController's color to Default color. Please help.
I created a tab bar app with a table view along with 3 titles(BOOKS) in the table view. I also loaded a Detail View when you tap one of the 3 Titles. Here is the question how can I load a separate Detail/view for EACH Title(Book) I want to tap the BOOK/Title in Table View and open the "Details" for each book/title and have Different details inclosed in EACH View.
I am able to create tab bar and navigation controller in it on MainWindow.xib. But my application's main screen is login screen. How will i insert login screen before MainWindow? Or how will i call my tab bar after login screen.
Actually i inserted another xib for login screen i.e. "LoginViewController" and called this from MainWindow using appdelegate, Also inserted another xib for creating TabBar-Navigation. But this doesent work.
//Calling TabBar-Navigation controller from LoginViewController
- (IBAction)changeGreetingid)sender {
UIViewController *targetViewController;
Yes! Thanks Brix.
Actually i am new to iPhone development. I will study this application and try to make changes in my application, because i added separate xib's for each screen.
In my application i didnt understand why "MainAppLeadComm" is not calling. I have put breakpoints in "- (void)applicationDidFinishLaunchingUIApplication *)application " but control is not going in this function. Only "dealloc" of "MainAppLeadComm" is called and login screen remain as it is on screen.
This helps so much. I have been struggling with something close to this. Maybe, you can answer my question:
I have been trying to build something similar but with a Navigation Controller rather than a Tab Controller? I would think it can be done, but have not tried it yet. Is there any downside to front-loading the multiple controllers in the app delegate?
This helps so much. I have been struggling with something close to this. Maybe, you can answer my question:
I have been trying to build something similar but with a Navigation Controller rather than a Tab Controller? I would think it can be done, but have not tried it yet. Is there any downside to front-loading the multiple controllers in the app delegate?
Thanks for your reply. Now my application works like following,
1. login screen view controller
2. then tab bar view controller in which i have added navigation controller and table views.
Now i want to come back to login screen from any of the navigation tab.
My appDelegate's "applicationDidFinishLaunching" function looks like.
I think I'm having a similar problem to ipnewbie from a few posts back, and wondering if any resolution was found.
I have a tab bar where some tabs are navigation controllers. Everything is set up in IB, and I'm pretty sure I've done that part right, as things are working as intended for the most part. My table views load and actions I wrote in didSelectRowAtIndexPath work fine.
However, for one of the navigation controllers that loads a table view, I've tried to create a nav bar button that pushes a child view. I've found that when I call the [self.navigationController pushViewController:animated] line, self.navigationController is nil. I found a way around this using:
but this is not really what I'm looking for, and isn't addressing the real problem. It seems that my table view is never being pushed onto the navigationController's stack in the first place. Has anyone had a simliar issue or know what I'm doing wrong? I have a feeling this is something very simple, but I just can't get it to work.
I can't tell you how helpful this thread has been to me. Its gotten me through many hours of pulling my hair out. One thing with this method that I am having trouble trying to do is overlay an image on top of the nav bar. I would love to make a little icon next to the title. Before this method I would just add an image view over the bar and insert my image. I know this idea is a little out of the norm but I would love to do it. Attached is an image of what I am trying to do. Thank you all for this great thread and any help would be so appreciated.
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
MyTableViewController *myTableViewController;
MySecondTableViewController *mySecondTableViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) MyTableViewController *myTableViewController;
@property (nonatomic, retain) MySecondTableViewController *mySecondTableViewController;
@end
@implementation AppDelegate
@synthesize window, myTableViewController, mySecondTableViewController, tabBarController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init]; // creates your tab bar so you can add everything else to it
myTableViewController = [[MyTableViewController alloc] init]; // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
[myTableViewController release]; // creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
mySecondTableViewController = [[MySecondTableViewController alloc] init];
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
[mySecondTableViewController release]; // does exactly the same as the first round, but for your second tab at the bottom of the bar.
tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; add both of your navigation controllers to the tab bar. You can put as many controllers on as you like, but they will turn into the more button like in the iPod program.
[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window
[window makeKeyAndVisible]; // makes the window visible
}
- (void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
} // lets go of everything else, thats so your program doesn't create any leaks of memory.
@end
I just typed up this quick App Delegate to show you how to do it. Yes, you do have rights to use whatever part of it you wish, and yes, you can ask any questions you like.
Please do note:
a ) I release the table views because they have been retained by the Navigation Controllers. Thus, I have doubled up and am taking double the memory. Once you have a nav controller holding your view, drop it. This saves memory. These nav controllers are set to drop automattically with their autorelease so there is no leak issue.
b ) if you need to add only one item to your tabBar for some strange reason, or just to test, change "arrayWithObjects: blah, blah2, nil" to "arrayWithObject: blah" and drop the nil.
Does this help you???
First, Thanks for the post and this great thread.
I've implemented the above code and it works great. However in my firstview (PeopleViewController) I added an NSLog(@"load view called for People"); to the -(void) loadView; method. When I run the app the console shows this message 7 times. I would have expected it only once. Can anyone explain this behavior?
I have been following this walkthrough and combined it with a multi level table with some success.
I have 5 basic .h/.m files
App Delegate
Navcontroller - nothing in the .h/.m files
HomeView - just text and logos
TableView - has all the info for the table and the push to the detail view
DetailView - takes the selected row from the table view, displays the page title and then selects an image based on the row and displays it.
The problem I am trying to overcome is if I leave the detailview and go to the home view, when I return back to the table tab the detail view is still displayed. I cant work out how to reset the table when I navigate away from the it. What do I need to add to get the table to reset.
I have tried adding code to the viewDidDisappear and viewdidunload in the detail view - no luck
Hey can you explain me with code a little bit about how you solved your problem with using table view inside a tab bar ?
Thanks in advance
Quote:
Originally Posted by BostonMerlin
I am having a bear of a time getting this to work. I've looked at it so many ways and followed tutorials on how to set each of the controllers separately but none show how to combine them all.
super simple bare bones sample
- create new Tab Bar Application
- create a new FirstScreenViewController .h and .m class
- add the appropriate TableView methods (as explained in other articles)
- Create a new FirstScreen.xib with a UIView
- Drop a TableView onto the View
- set the files owner to point to FirstScreenViewController
- Save to project
- load up MainWindow.xib
- set the first tab to be a Navigation Controller
- set the first tabs xib to point to the FirstScreen.xib file
Save and run. I see a TabBar window with two buttons. the first button has a navigation controller toolbar up top and i can see the outlines of an empty Table View. Looks great so far.
Load up my FirstScreenViewController.xib file. Connect the view, tableview datasource and tableview delegate to point over to the Files Owner. Save
Run the project, hangs for a second then dumps me back to xcdoe with an unhandled error. Take out the datasource and delegate connections and i'm back to see a blank tableview.
Any Ideas? I know this is a long winded desription.. sorry. I'm able to create a single page application with a tableview with no problem but when i dump this into a tabbar controller it craps out.
1. Took UITabBarController and UINavigationController in first tab.
2. In first navigation controller i took UISegmentedControl.
3. On segment selection i am changing views.
4. On first segment i am showing UITableView and on second segment i am showing UIImageView.
5. If i select any row from UITableView i want to display details for that row, by calling another ViewController.
But on selection of table cell it is not going ahead.
Please see attached sample code.
In DetailViewController i am calling showDetails() and in that function i am calling pushViewController for SecondTableView but it is not working. Please help.
searching for the same thing i got your post.
Did you able to use a separate initial view except from the one when Tabitem selected?
I am looking for such an solution.