Based on your code, it looks really good. But i have a simple
and maybe stupid question.
do you make the MyTableViewController with code or with IB mixed.
If you use IB do you need to initialize it differently ?
like initWithNibfile
and make code adjustments in viewDidLoad ?
Thanks
You can use either, but I prefer code. The fact is that for UITableViewControllers, everything is done in code anyway - so why add IB into the mix?
If you don't override the - (void)loadView{ } method, it creates the table view for you that you would create in IB - why add IB when you can get it without doing anything?
To initialize a UITableViewController programmatically, you have two options:
init (creates a plain table view) or initWithStyle (creates with the style you specifiy).
I recommend initWithStyle, as init calls initWithStyle anyway.
You can use initWithNibName:bundle if you want to use IB too...
hey, so I have been looking to make it work but I can't, so I start to thing it's not possible to do it like I want. To be more clear I am looking for doing something like the iCalendar app when you can choose list, day and month and after go to a details view.
I tried also with a toolbar instead of a tabbar.
If you have any idea...
Man, im so glad i found this thread...!!! ive read it so many times, but i still lack some basic understanding .. so heres one more embarassing question!..
I started my project selected window based app. that'll give me oppertunity to learn more.. i think
I've made 2 views and a central view. Its mainly for learning how everything works. the issue is with one View1.xib
its got:
the fileowner class is set the vew1controller that i created.
the two iboutlets are: those controlles tableview and searchbar declared in view1controller.m
As you can see, i wanted to add stuff to table view. but how do i go about doing that? since theres no template thats got the tableView functions inside the code.. and also cuz i've manually written their View1controller class at the moment and. I though should i be adding a new file - UITableViewController subclass (that will atleast give the method names) and connect that to the table view?How do I do that? but what happens then to the viewcontroller i had already set. ?
The connections are killing me.. or is there conceptually a flaw in my the design.
I can successfully display the view.xib with searchbar and table view. but any functional tryouts completely fail..
anyhelp is appreciated..
I have created a tab bar app with 4 tabs using IB which is working fine, one tab i have set as a 'Navigation Controller' within the View Controllers window of the Tab Bar Controller Attributes, and have set my rootviewcontroller of the view to 'ChooseCardView.nib'
my ChooseCardViewController, loaded within the nav controller of the tab, is a table view, with a disclosure button which when clicked, should load another view on the navigation stack.
im having trouble interfacing with the navigation controller to be able to push the new view onto the stack, could anyone shed some light on the best way to do this?
You can use either, but I prefer code. The fact is that for UITableViewControllers, everything is done in code anyway - so why add IB into the mix?
If you don't override the - (void)loadView{ } method, it creates the table view for you that you would create in IB - why add IB when you can get it without doing anything?
To initialize a UITableViewController programmatically, you have two options:
init (creates a plain table view) or initWithStyle (creates with the style you specifiy).
I recommend initWithStyle, as init calls initWithStyle anyway.
You can use initWithNibName:bundle if you want to use IB too...
Actually what you say makes lots of sense, there is no use of IB for a subclass of UITableViewController. But what if I want to use UIViewController and use a View with a table in it and maybe other controls too. For that, I think a mix of IB and code would be good. dont you think so ?
Is there any way to load the second tab directly in background?
so that the user doesn't have to wait when he hits the second tab. I want to show the content directly (which should be loading at the app launch)
Is there any way to load the second tab directly in background?
so that the user doesn't have to wait when he hits the second tab. I want to show the content directly (which should be loading at the app launch)
This is an excellent question. I have an application with a web tab, and an RSS tab. Both of these are painfully slow to load if you're not on Wi-Fi. I hope someone can answer this.
Perhaps you can ask that view to load in ApplicationDidFinishLaunching? The downside is, I think it will eat quite a bit of memory for something that the user may never see.
This is an excellent question. I have an application with a web tab, and an RSS tab. Both of these are painfully slow to load if you're not on Wi-Fi. I hope someone can answer this.
Perhaps you can ask that view to load in ApplicationDidFinishLaunching? The downside is, I think it will eat quite a bit of memory for something that the user may never see.
Hey same to me
I have a RSS Loader too. I don't want to bother the user to wait for the content.
You could load the content of the second tab with different setters and getters methods. but it is not a nice solution
How does the tabBarController push the selected tab?
The below code has been really helpfull, much prefer programatically creating view controllers, before I was just mixing them up.
Simple question, have got this up to the build and run stage, I get a window displayed with a tab bar view controller look, but when I select one of the tabs it quits with an Ex_Bad_access error with the message in the control window as follows
2009-05-15 00:01:28.490 SDKthread[27374:20b] *** -[CALayer isEqualToString:]: unrecognized selector sent to instance 0x531700
2009-05-15 00:01:28.491 SDKthread[27374:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CALayer isEqualToString:]: unrecognized selector sent to instance 0x531700'
2009-05-15 00:01:28.493 SDKthread[27374:20b] Stack: (
Where am I meant to tell the tabBar controller what navigation controller to to load, i found this method that looks like i need to initialize
- (void)tabBarControllerUITabBarController *)tabBarController didSelectViewControllerUIViewController *)viewController{
Any help would be MUCH appreciated,
Thanks
Ali
Quote:
Originally Posted by DevTeamOfOne
Code:
@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.
Ok I have made you a quicktime video, sorry no audio. ... Download it here.
I wanted to send you a private thank-you but couldn't find the link ... so here's a public one. THANK YOU for making that video!
One of the distractions I've encountered in my online travels is all the partisan back-and-forth between using Interface Builder and coding by hand. Speaking/writing for myself, it's important to me that I appreciate and know how to use BOTH methodologies.
Between development books by Sadun and Mark/LaMarche, I think I've struck a happy medium in that regard, but I find succinct IB examples lacking on occasion. Mixing in nav controllers plus table views, along with a tab bar was one of those areas. Yours drove the point home so well and with no muss/fuss, I just wanted to say thanks.
Wow, can I just say thanks for this thread it has been really useful in helping me mix a tab bar and navigation view.
One (possibly quite dumb) question... Can I bring up the tabBar controller and all the navigation controllers in each tab at a later point in the application.
example - when the app first loads it loads an initialView.xib, in that view the user presses a UIButton that then loads the Tab Bar Controller. I am just unsure how to go about this.
Should the tabBar controller be in a seperate xib, the window.xib or created programatically and should I still create it using the app delegate or would that load the tabBar straight away, which would waste memory?
Hi:
I have a tab bar app with three tabs. One of the views (UIView) contains a web view and a table view. I wanted to add a "detail view" to the table so I followed the tutorial on this web site for creating a simple detail view but I can't seem to push the "detail view" created to the front. I suspect that this is because my view is not a UITableView or something. I built everything in IB. I don't get any errors. The code below is called but I just don't see the new view. My question is where is the new view going and how can I fix this.
This is the code that is supposed to push the detail view: It is located in a file called ThirdViewController.m that controls the third tab's view.
Hi:
I figured it out. This is for people who are trying to get a detail view from a table that is either not full-screen (so it can not use a uitableviewcontroller) or who have already built their app with a tab bar instead of a nav bar.
Follow the great tutorial on this site for creating a detail view and then use:
I have a search bar that is attached to the top of the table view that works fine before I used the tabbarcontroller, but after i integrated it in, it did not work anymore. any ideas why? it still shows up in IB, but when i test it, nothing shows up.
never mind, i figured it out, by
initWithNibName:@"the name of your class" bundle:nil];
instead of just init the class. ex:
rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
Ok I have made you a quicktime video, sorry no audio.
Tab Bar Demo
In this app I have a Tab Application with 2 tabs. Both tab views are set to Navigation Controllers - that is why you see a navigation bar in both tabs. The first view in each navigation controller is set to load from seperate XIBs. Both FirstView.xib and SecondView.xib are UITableViewControllers. I created 2 UITableViewController subclasses which each xib's File Owner class are set to (That is the blue square).
Extra notes:
1. I had to delete the SecondViewController.m and .h files because they were subclasses of UIViewController and not UITableViewController. I could have changed the code but if you use the class wizard you get all of the table methods in the file when it is created.
2. I had to add the CoreGraphics framework because it would have failed to link the CGRectZero symbol which is needed to build. Apple should have included this by default.
3. Oops I didn't really need to delete the original SecondView.xib I could have just edited it.
Navigation controller + TableView, Code OK, IB not working
I did a test on this too.
First I have TestNavigationControllerAppDelegate create
TestNavigationControllerViewController
Using IB, TestNavigationControllerViewController.xib, I created its view with one button.
I'd like to add NavigationController, which root view controller is MyTableViewController.
I defined an IBOutlet for the NavigationController.
@property (nonatomic, retain) IBOutlet UINavigationController *theNewNavigationController;
I add one UINavigationController, assign this root view controller with NIB name MyTableViewController.xib. and also bind the outlet theNewNavigationController.
I got the error:
2009-07-06 00:10:56.143 TestNavigationController[2913:20b] *** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xd29050
2009-07-06 00:10:56.144 TestNavigationController[2913:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xd29050'
2009-07-06 00:10:56.146 TestNavigationController[2913:20b]
Any idea on this? What differences between IB and the code?
I got the error:
2009-07-06 00:10:56.143 TestNavigationController[2913:20b] *** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xd29050
2009-07-06 00:10:56.144 TestNavigationController[2913:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xd29050'
2009-07-06 00:10:56.146 TestNavigationController[2913:20b]
Any idea on this? What differences between IB and the code?
Q: Should UIViewController should be UITableViewController? (This may need to be changed in the XIB.)
Meanwhile, here's a VERY handy utility for getting an Objective-C view of XIB files:
(I linked to Erica's article because it provides a nice third-party endorsement and explanation, but credit ultimately goes to Adrian Kosmaczewski.)
I often use this tool when I find I'm ready to move certain XIBs (or portions of them) to code. I don't do it exclusively, but it sure helps bridge the gap and gives you a nice peek under the proverbial hood.
Does anyone still have access to this vid? I'm a late comer, but this thread has proven invaluable and I would like to try both methods thoroughly.
Cheers!
The video is still available. After entering the requisite CAPTCHA and picking "Download File", be sure to pick "Regular download" at the very bottom and not "Download link" toward the top. (Yes, this is confusing. Whee ...)
(I linked to Erica's article because it provides a nice third-party endorsement and explanation, but credit ultimately goes to Adrian Kosmaczewski.)
I often use this tool when I find I'm ready to move certain XIBs (or portions of them) to code. I don't do it exclusively, but it sure helps bridge the gap and gives you a nice peek under the proverbial hood.[/quote]
Oh boy, do I need help. I have been reading and rereading and I'm now going in circles. Long story short, I used the awesome video tutorial from earlier in this post to create a 4 tab bar setup. With that I was able to put in custom icons. So far so good. Now I want to put a drill down into the table view of the first tab bar. I tried using the sample code from the following site:
I do get the initial view of the data in the table view of the first tab bar. But whenever I click any of the "items" to take me to the next level of the drill down, it freezes up. I have tried for days, searched and experimented with different coding, and my wee brain has seized up much like the coding. Can anyone please help?
I do get the initial view of the data in the table view of the first tab bar. But whenever I click any of the "items" to take me to the next level of the drill down, it freezes up.
There's a typo that doesn't seem to affect the Simulator, only devices.
On line 23 of DrillDownAppDelegate.m, change "data.plist" to "Data.plist" instead.
Also, if you are building for iPhone OS 3.0 vs. 2.2.1, change line 67 of RootViewController.m so that cell.text reads as cell.textLabel.text instead. (The text property was deprecated in 3.0.)
Finally, if you try to build for the device, you probably did this already, but make sure the App Identifier matches your provisioning profile (Cmd-Option-E, Properties, Identifier).
By making those changes on a fresh download of the source, that ought to do the trick!