Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView selection changed event in Monotouch

I created a custom hierarchy of views, somewhere in this hierarchy is a UITableView, with an outlet called TableView, so i can reach it from backend code.

I want to create and push a new view to the root viewcontroller's view stack when an item in that list is selected, but i can not find any relevant events on the UITableView.

All controls were defined using Interface builder in .XIB files

Am i looking in the wrong place?

thanks in advance.

like image 464
Timothy Groote Avatar asked Dec 22 '22 15:12

Timothy Groote


1 Answers

Yes, you are looking in the wrong place. To use UITableView's "events", you have to implement a UITableViewSource and assign it to your table view. The most common way to do it is in the table view's controller as a nested class:

private class MyTableSource : UITableViewSource
{

    public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
    {

        // Do something for the selected row

    }

    // Override both RowsInSection and GetCell methods!

}

You then set the MyTableSource class to the table view's Source property:

myTableView.Source = new MyTableSource();

Note that the UITableViewSource class does not exist in Objective-C. It is merely a MonoTouch class that hosts both UITableViewDataSource's and UITableViewDelegate's methods, making things a lot simpler.

like image 54
Dimitris Tavlikos Avatar answered Dec 24 '22 04:12

Dimitris Tavlikos