1

我有一个运行良好的TabBarController应用程序,DialogViewController除了在初始加载时表格为空,直到我触摸它或导航到另一个选项卡并返回(http://cl.ly/3I0r1v2b420t0L1X1h2w)。

我已确认Root已设置。我试过发出一个ReloadData()之后。我也试过TableView.Source直接设置。在任何情况下,TableView直到发生另一个动作,它才会显示任何内容。

这发生在模拟器和 iPhone 上。

知道为什么会这样吗?

public partial class PapersView : DialogViewController
{
    public PapersView () : base (UITableViewStyle.Plain, null, true)
    {
        EnableSearch = true; 
        AutoHideSearch = true;
        SearchPlaceholder = @"Find Papers";
    }

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

        MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
        var svc = new PaperService ();
        svc.GetPapers (onPapersReceived, onErrorReceived);
    }

    private void onErrorReceived (string error)
    {
        MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
    }

    private void onPapersReceived (List<PaperNode> papers)
    {
        MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

        Root = new RootElement ("Papers") {
                from node in papers
                    group node by (node.paper.title [0].ToString ().ToUpper ()) into alpha
                    orderby alpha.Key
                select new Section (alpha.Key){
                    from eachNode in alpha
                    select (Element)new WhitePaperBible.iOS.UI.CustomElements.PaperElement (eachNode)
        }};

        TableView.ScrollToRow (NSIndexPath.FromRowSection (0, 0), UITableViewScrollPosition.Top, false);
    }
}
4

2 回答 2

3

Curtis Bailey 指出我在 MonoTouch 邮件列表上查看 InvokeOnMainThread。这解决了这个问题,因为异步服务调用在后台线程上,回调也是如此。

    private void onPapersReceived (List<PaperNode> papers)
    {
        MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

        InvokeOnMainThread (delegate {
            Root = new RootElement("Papers") {
                    from node in papers
                        group node by (node.paper.title [0].ToString ().ToUpper ()) into alpha
                        orderby alpha.Key
                    select new Section (alpha.Key){
                        from eachNode in alpha
                        select (Element)new WhitePaperBible.iOS.UI.CustomElements.PaperElement (eachNode)
            }};

            TableView.ScrollToRow (NSIndexPath.FromRowSection (0, 0), UITableViewScrollPosition.Top, false);
        });
    }
于 2012-04-11T01:40:15.527 回答
1

尝试仅填充现有根而不是创建新根。

如果您查看 DialogViewController 的 MonoTouch.Dialog 源代码,您应该会找到 PrepareRoot() 方法。看看它在哪里被调用,它应该开始有意义。

于 2012-04-10T22:54:56.407 回答