I'm developing an iPhone app. I'm using a UITable subclassing UITableViewController. I added a NavigationBar to the view: UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];[self.tableView addSubview:navBar];
, now the problem is that the navigation bar scroll down with the table and it's what I want to avoid. Is possible to avoid it using the UITableViewController?
views:
65answers:
1
+2
A:
You say
I'm using a UITable subclassing UITableViewController
I guess you are using a subclassed UITableViewController which, naturally, holds a UITableView. Your problem is caused by the fact, that you inserted the NavigationBar into the UITableView, or, more precisely, into the UIScrollView which is part of the TableView. Depending on your needs, you have two options:
- If you want your app to behave like e.g. Mail (so your TableView will be just one element in a structure of views, through which you can dig down), you should a UINavigationcontroller and make your TableViewController the NavigationController's first view, like when you open the "Navigation based"-Template in Xcode. The UINavigationcontroller will already contain a UINavigationBar, so there isn't much you have to worry about.
- If, for some reason, that's not what you want, you will have to create a UIView which holds your UINavigationBar as well as the UITableView. Since accomplishing such a setup with a UITableViewController is known to be rather difficult, you might want to ditch your TableViewController and replace it with a simple ViewController, which implements both the "UITableViewDelegate"- and "UITableViewDataSource"-Delegate. See this post for further help.
Phlibbo
2010-09-24 16:03:24
Thanks, i choose the 2nd option, i read the link you post but now i have a new question because I always used UItable with the UITableViewController: I added a UITable on the xib file, I wired it with the IBOutlet on the .h file, i added UIViewController <UITableViewDataSource, UITableViewDelegate> on .h file, at the end i implemented all the methods to manage the table (numberOfRowsInSection: or - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ) as usual with the UITableView Controller but data are not load!
PiccoloBuddha
2010-09-25 08:36:02
Just resolved! I only should link the delegate and the data source to the file's owner! Thanks for your help!!
PiccoloBuddha
2010-09-25 08:55:19
You're welcome. Please mark my answer as accepted then.
Phlibbo
2010-09-25 09:35:26