MonoTouch:如何使用UITableViewController作为UITableView的数据源?

Kru*_*lur 0 c# uikit xamarin.ios

我正在使用带有静态内容的故事板和表格视图.在内部,似乎UITableViewController隐含地成为了它的来源UITableView.

如果我现在想要对静态内容产生影响,我将不得不重写表源的方法.在ObjectiveC我可以放置

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return @"HELLO!";
    else {
        return [super tableView:tableView titleForHeaderInSection:section];
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,该方法将被覆盖.但在MonoTouch中,这不起作用.请注意,我不想创建委托或数据源的新实例.对于静态单元,控制器源/委托.在ObjectiveC中,这是通过使控制器实现相应的协议来完成的.

以下是我提出的与此主题相关的问题,但现在我无法将解决方案转换为MonoTouch:

如何覆盖tableView:titleForHeaderInSection:调整静态UITableViews的节头?

Kru*_*lur 5

在Xamarin网站的精彩教程中找到了解决方案:http://docs.xamarin.com/ios/tutorials/Events%2c_Protocols_and_Delegates

" Export"属性可以解决问题!

public partial class TestController : UITableViewController
    {
        public TestController (IntPtr handle) : base (handle)
        {

        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
        }

        [Export("tableView:titleForHeaderInSection:")]
        public string TitleForHeaderInSection(UITableView oTableView, int iSection)
        {
            return "TEST";
        }
    }
Run Code Online (Sandbox Code Playgroud)