简体   繁体   中英

How can I programmatically add more than just one view object to my view controller?

I'm diving into iPhone OS development and I'm trying to understand how I can add multiple view objects to the "Left/Root" view of my SplitView iPad app. I've figured out how to programmatically add a TableView to that view based on the example code I found in Apple's online documentation...

RootViewController.h

@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate, UITableViewDataSource> {

    DetailViewController *detailViewController;

    UITableView *tableView;

    NSFetchedResultsController *fetchedResultsController;
    NSManagedObjectContext *managedObjectContext;
}

RootViewController.m

- (void)loadView
{
    UITableView *newTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
    newTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    newTableView.delegate = self;
    newTableView.dataSource = self;
    [newTableView reloadData];

    self.view = newTableView;
    [newTableView release];
}

but there are a few things I don't understand about it and I was hoping you veterans could help clear up some confusion.

  1. In the statement self.view = newTableView , I assume I'm setting the entire view to a single UITableView. If that's the case, then how can I add additional view objects to that view alongside the table view? For example, if I wanted to have a DatePicker view object and the TableView object instead of just the TableView object, then how would I programmatically add that?
  2. Referencing the code above, how can I resize the table view to make room for the DatePicker view object that I'd like to add?

Thanks so much in advance for your help! I'm going to continue researching these questions right now.

创建一个您分配为视图控制器视图的容器视图,然后将内容视图作为子视图添加到此容器视图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM