异步调用后调整MonoTouch.Dialog StyledMultilineElement的大小

时间:2011-09-15 20:09:20

标签: xamarin.ios monotouch.dialog

我正在玩MonoTouch.Dialog,并编写了一些代码来展示一些推文。问题是当我加载StyledMultilineElement 异步时,表格单元格太小而且单元格都已聚集在一起。当我同步加载它们时(即没有QueueUserWorkItem / InvokeOnMainThread部分),它们看起来绝对完美

有没有办法让表格单元格重新计算它们的高度?

// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{           
    window.AddSubview(navigation.View);

    var tweetsSection = new Section("MonoTouch Tweets"){
        new StringElement("Loading...") //placeholder
    };

    var menu = new RootElement("Demos"){
        tweetsSection,
    };

    var dv = new DialogViewController(menu) { Autorotate = true };
    navigation.PushViewController(dv, true);                

    window.MakeKeyAndVisible();

    // Load tweets async
    UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
    ThreadPool.QueueUserWorkItem(delegate {
        var doc = XDocument.Load("http://search.twitter.com/search.atom?q=%23MonoTouch");
        var atom = (XNamespace)"http://www.w3.org/2005/Atom";

        var tweets = 
            from node in doc.Root.Descendants(atom + "entry")
            select new { 
                Author = node.Element(atom + "author").Element(atom + "name").Value, 
                Text =  node.Element(atom + "title").Value
            };
        var newElements = 
                from tweet in tweets
                select new StyledMultilineElement(
                    tweet.Author, 
                    tweet.Text);

        InvokeOnMainThread(delegate {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
            tweetsSection.Remove(0);                                    
            tweetsSection.Add(newElements.Cast<Element>().ToList());    
        });
    });

    return true;
}

1 个答案:

答案 0 :(得分:3)

尝试在对话框视图控制器的顶级UnevenRows元素上设置Root属性,在本例中为“menu”:

menu.UnevenRows = true