views:

65

answers:

1

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?

+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:

  1. 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.
  2. 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
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
Just resolved! I only should link the delegate and the data source to the file's owner! Thanks for your help!!
PiccoloBuddha
You're welcome. Please mark my answer as accepted then.
Phlibbo