0

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

如果我现在想影响静态内容,我将不得不覆盖表源的方法。在ObjectiveC中,我可以放置

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

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

这是我提出的与该主题相关的问题,但现在我将解决方案转换为 MonoTouch:

如何覆盖 tableView:titleForHeaderInSection: 以调整静态 UITableViews 的节标题?

4

2 回答 2

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";
        }
    }
于 2012-05-22T16:48:48.713 回答
-1

在 Mono Touch 中,您必须创建一个 DataSource Delegate。

就像这篇博文中的演示一样:http: //sabonrai.wordpress.com/2009/08/28/monotouch-sample-code-uitableview/

        public override string TitleForHeader (UITableView tableView, int section)
        {
        //do your stuff 
        }   

如果要自定义标题部分的标题,只需覆盖 TableViewDelegate 中的 titleForHeaderInSection。

于 2012-05-22T16:18:40.797 回答