views:

135

answers:

5

Hi there

I'm trying desperately to design my UI programmatically. But I think I'm in trouble to understand the concept. Basically I want a UI which contains different UIViews and a UITableView.

But now I'm stuck with the UITableView...

So my "main view" which should contain all these views is called AddListViewController(it inherence from UIViewController).

In the loadView method of this class I'm trying to add a table, but no chance. Has anyone a good example for me. I'm really dont see the point for a separate UITableView and UITableViewController.

Thx a lot

+2  A: 

Just create your UITableView and add it as subview:

UITableView *table = 
  [[UITableView alloc] initWithFrame:CGRectMake(x, y, width, height)
                       style:UITableViewStyleGrouped];

...

[self.view addSubview: table];
[table release];
Tuomas Pelkonen
+2  A: 

You can create a new UITableView, very simply like this:

UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
[tableView setDataSource:self];
[tableView setDelegate:self];
[self.view addSubview:tableView];
[tableView release];

EDIT: The above answer beat me to it.

Tom Irving
Barely, but I left the data source and delegate out :)
Tuomas Pelkonen
+1  A: 

In loadView, you have to make every view - including the overall view associated with the view controller.

You perhaps want to do what you are trying to do in viewDidLoad instead?

Kendall Helmstetter Gelner
A: 

Ok where was my head :-) now that works. But if I want to add a delegate and a datasource the app chrashes! Any idea?

- (void)loadView {
NSLog(@"AddListViewController");
ShareListViewController *shareListViewController = [[ShareListViewController alloc] init];

UITableView *shareListView = [[UITableView alloc]initWithFrame:CGRectMake(100, 30, 100, 200) style:UITableViewStylePlain];
shareListView.delegate = shareListViewController;
shareListView.dataSource = shareListViewController;


[self.navigationController.view addSubview:shareListView];

[shareListViewController release];
}

and my ShareLIstViewController

@interface ShareListViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{

}

@end
gabac
A: 

i many be late in answering but still i am answering it use:

shareListView.delegate = self;
shareListView.dataSource = self;
pankaj