2

I'm playing with MonoTouch.Dialog and written some code to show some tweets. The problem is that the table cells are too small and the cells are all bunched up when I load the StyledMultilineElements asynchronously. They look absolutely perfect when I load them synchronously (i.e. without the QueueUserWorkItem/InvokeOnMainThread part)

Is there a way of getting the table cells to recalculate their height?

// 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;
}
Duncan Smart
  • 31,172
  • 10
  • 68
  • 70

1 Answers1

3

Try setting the UnevenRows property on your top level Root element of your Dialog View Controller, in this case "menu":

menu.UnevenRows = true
SoftSan
  • 2,482
  • 3
  • 23
  • 54
miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
  • Cheers Miguel that along with tweaking the GetHeight code did the trick. I shall submit a pull request for the latter. – Duncan Smart Sep 18 '11 at 09:31