开发者

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.


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.


The RowSelected event happens in the UITableViewSource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜