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

标签 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;
}

最佳答案

尝试在对话框 View Controller 的顶级 Root 元素(本例中为“menu”)上设置 UnevenRows 属性:

menu.UnevenRows = true

关于xamarin.ios - 异步调用后调整 MonoTouch.Dialog StyledMultilineElement 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436870/

相关文章:

c# - 如何在 Monotouch 中实现多个委托(delegate)?

xamarin - 当 UIWebView 请求开始加载时,不会调用自定义 UIWebViewDelegate 的 ShouldStartLoad

ios - 根据Xamarin.iOS中的Frame调整UILabel的字体大小

xamarin.ios - MonoTouch.Dialog:通过触摸 DialogViewController 中的任意位置来关闭键盘

xamarin.ios - 为什么 DateElement 选择器上没有后退按钮?

c# - 单点触控对话框。带有 Elements API 的按钮

c# - 如何导入/包含包含对 Xamarin Studio/MonoTouch 静态内容文件的引用的文件

xamarin - 减少 AppStore 应用程序大小 : Remove System. Xml?

c# - DialogViewController 打破 UINavigationController 路径

c# - 继承/设置 RadioGroup 的 BackgroundView 生成的 DialogViewController TableView (MonoTouch.Dialog)