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/

相关文章:

xamarin.ios - Monotouch.Dialog iOS 7 自动外观升级?

ios - 如何使用 outlets 和 IB 为表格 View 部分创建自定义标题 View

c# - 使用 MonoTouch.Dialog 时更改 TabBarController 和 NavigationController

c# - 将图像添加到 Monotouch.Dialog 中的部分

git - 创建一个 git post-receive 触发器(应该适用于 Mac OS X 上的 Xamarin Studio)

c# - 在 Xamarin.iOS 中使用 EKEvents 将列表序列化为 JSON

c# - 如何在 Xamarin.Android 和 Xamarin.iOS 上使用 dllmap?

xamarin.forms - 如何在 Xamarin.Forms 中检查暗模式

xamarin.ios - 如何在命令行 Xamarin 构建中强制重新生成 *.designer.cs 文件?

c# - 使用 MonoTouch.Dialog 根据 RadioElement 的值显示多个 RootElement