0
votes

When you drag a Table View Controller from the Xamarin toolbox onto an existing ViewController in your storyboard, and then give it a class name, that class that is automatically created inherits from UIViewController. If you drag the Table View Controller onto an empty space on the storyboard and give it a class name, the class that is automatically created inherits from UITableViewController.

UITableViewController has a property called TableView, which has a property called Source, where you can set the DataSource for the table by giving it a UITableViewSource:

TableView.Source = datasource;

I don't know how to do this if the Table View Controller inherits from UIViewController. Can I change the class to inherit from UITableViewSource without causing problems, or does a Table View Controller embedded in another view controller have to inherit from UIViewController?

If I can't change the inheritance of the class, what is the best way to set the source of the Table View Controller that inherits from UIViewController?

2

2 Answers

2
votes

You should add a UITableView to an existing controller, not a UITableViewController.

1
votes

My two cents for another possible scenario. In those cases when a TableView occupies whole ViewController and there aren't any other controls/widgets in the page you can use UITableViewController instead of UIViewController. You can drag in the UITableViewController instead of the UIViewController.