Reputation: 11
I have this class to create the date source. How do I create a UIViewController
using this class?
public partial class JogosSource : UITableViewSource {
List<TableItem> tableItems;
string cellIdentifier = "TableCell";
public JogosSource (List<TableItem> items)
{
}
public override int RowsInSection (UITableView tableview, int section)
{
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
}
}
Upvotes: 0
Views: 320
Reputation: 33428
I'm not pretty sure I understand your question.
UITableViewSource
is a class that combines UITableViewDelegate
and UITableViewDataSource
into one convenient class that contains the methods of both.
So, if you want to use that class, JogoSource
in your case, as written in MT doc you need to
Assign an instance of this object to the UITableView.Source property.
To create a UITableView
element you could follow three different ways:
Subclass an UITableViewController
(this class has a table view its own)
Subclass a UIViewController
with its own XIB, drag the table within the main view and link it with an outlet
Subclass a UIViewController
(with its own XIB, this is optionally), create the table by code
Setting the Source
for your table view instance could be done in ViewDidLoad
method. Here you are sure that outlets, for example, are set up correctly.
this.YourTable = new JogoSource(yourItems);
Simple advice
Usually, when you deal with a UITableViewSource
class you could also inject within its constructor the controller that "controls" that source. This could be useful for example in situations when you deal with UINavigationController
.
So, I would change the ctr of JogoSource
as
public JogosSource (UIViewController injectedController, List<TableItem> items)
{
// _controller is a private var of type UIViewController
_controller = injectedController;
}
If your controller is inserted, for example, in a UINavigationController
and you need to show some details when you select a row, by means of _controller
you access the parent (an instance of UINavigationController
).
P.S. There are other possibilities to create a table but I listed the main ones. Furthermore, check the code since I've written by hand.
Hope that helps.
Upvotes: 1