[MonoTouch] Subscribing to ScrollAnimationEnded on a uitableview has strange results?

victoria iminurbase at hotmail.com
Wed Mar 7 00:19:57 UTC 2012


Hello list, hope you can shed some light on this odd issue we're having.

Today I helped track down a really obscure bug. What it came down to is
this: deep in the code an uitableview had its ScrollAnimationEnded
subscribed to, and when that happened the uitableview.Source for some reason
got set to null.

I think the best way I can explain it is with a simple test case:

---
    class DoNothing : UITableViewSource
    {
      public override int RowsInSection (UITableView tableview, int section)
{ return 0; }
      public override UITableViewCell GetCell (UITableView tableView,
NSIndexPath indexPath)
      {
        return new UITableViewCell();
      }
    }
 
    public override void ViewDidLoad ()
    {
      UITableView tableview = new UITableView();
      tableview.Source = new DoNothing();
 
      Console.WriteLine("source null? " + (tableview.Source == null));  //
false
      tableview.ScrollAnimationEnded += (s, e) => { };
      Console.WriteLine("source null? " + (tableview.Source == null));  //
true, what happened here?
    }
---

we worked around the problem by saving the uitableview.source just before
subscribing to the event, then in the event handler we simply set the source
again. This seem to work and luckily we don't really need the source until
the event has fired, but I can't for my life understand WHY .source is
cleared on subscribing to the event, or what else happens that we haven't
noticed yet (hint: this is the real question that worries me).

This by the way, doesn't work either:

var tmp = tableview.Source;
tableview.ScrollAnimationEnded += (s, e) => { };
tableview.Source = tmp;

Because setting Source to tmp clears the subscribed event. Is this really
expected behavior, are we missing something? Or maybe, what is the proper
way to subscribe to ScrollAnimationEnded without strange side effects?

/ V

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Subscribing-to-ScrollAnimationEnded-on-a-uitableview-has-strange-results-tp4451815p4451815.html
Sent from the MonoTouch mailing list archive at Nabble.com.


More information about the MonoTouch mailing list