1

On my storyboard I have a ViewController and I want to add a UITableView with 1 section and 2 static cells. That's all I'm doing right now but I get this error when compiling.

Static table views are only valid when embedded in UITableViewController instances

What am I missing?

Dalee Davis
  • 981
  • 8
  • 19
thisiscrazy4
  • 1,905
  • 8
  • 35
  • 58

2 Answers2

1

Look at This question. Basically the same thing.

Any further questions, just ask! :)

Edited stuff:

    UITableViewController *controller = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.view addSubview:controller.tableView];

Then all you need to do is adding the UITableViewDataSource in the header file and you need the datasource methods:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if([indexPath row] = 0){
do something
}else if([indexPath row] = 1){
do something else
}
Community
  • 1
  • 1
Tom
  • 346
  • 2
  • 18
  • The answer mentions to "Add a UITableViewController to your view." I can add a UITableView to a view but how would I add a UITableViewController to a view? – thisiscrazy4 Jan 05 '13 at 03:50
  • Hmm... Guess you would have to add it programmatically. Changing my answer. – Tom Jan 05 '13 at 03:58
0

I think you just have to set datasource and delegate methods of the tableView in your .h file

@interface viewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

and then link it to your tableView in storyboard.

Please notify if it works..

Cashew
  • 1,466
  • 2
  • 16
  • 21
Ashutosh
  • 2,215
  • 14
  • 27
  • Wasn't this what you couldn't do with static tableviews? Haven't tried it myself, but the topic and my linked question seems to imply that... – Tom Jan 05 '13 at 14:19