Linux world
Linux world

Reputation: 3768

which type of application will allow me to create the user defined table view with navigation support

i want to display the table view and above that i hav some buttons to display ... which type application is better to fulfill this and it must support navigation...

i hav tried navigation based app but it is not allowing to move table view in root view controller...

Upvotes: 0

Views: 78

Answers (1)

TomSwift
TomSwift

Reputation: 39512

The "application type" is purely used when selecting a template used to generate the initial app. Once you have your app generated you're free to do whatever you want with the structure.

Since you say you need navigation (push, pop view controllers, with a back button in the nav bar) you should start with the Navigation-based-application template. This will generate an app where the root-view-controller is based on a UITableViewController.

Now, for the buttons you want above the UITableView. Here is where you have a few options:

1) place the button(s) in the navigation bar. It's easy to add a single button to the right-hand side of the nav bar:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle: @"My Button" style: UIBarButtonItemStyleBordered target: self action: @selector( onMyButton: )] autorelease];
}

It's slightly harder to add more than one button but it can be done.

2) place the buttons in the UITableView header. In the nib for your root-view-controller, create a new view (size it roughly 320x100) and add your buttons. Attach it to a UIView* IBOutlet in your RootViewController called something like "_buttonContainer", declared like this:

@interface RootViewController : UITableViewController 
{
    IBOutlet UIView*    _buttonContainer;
}

Then, in viewDidLoad, make that buttonContainer view the header for your table:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.tableHeaderView = _buttonContainer;
}

This will place your buttons above the tableView rows, but the buttons will scroll when the tableview is scrolled. Don't forget to hook up your buttons too.

3) This is the option I think you were trying to achieve -- namely shifting the whole tableview down and placing buttons above it. To do this, dont use a UITableViewController as a basis for your rootViewController. The UITableView is THE view of the controller and it is intended to fill the screen/window (within any other container viewcontrollers...). Instead, add a new UIViewController-based class to the project (be sure to select "With XIB for user interface", and unselect "UITableViewController subclass"). In interface builder drag your buttons onto the view, and also drag a new UITableView onto the view - and position everything how you want it. Hook up the tableview datasource and delegate to the view controller object (which is the "Files Owner" object).

Now, in the class definition you need to declare that your new ViewController is a tableview delegate and datasource:

@interface MyNewRootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

}

@end

And, you need to add the minimum set of datasource methods to support the tableview:

@implementation MyNewRootViewController

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 0;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...

    return cell;
}

Hook up your buttons, and that's about it... You can update MainWindow.xib to use your new rootviewcontroller instead of your old one.

Upvotes: 1

Related Questions