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

Rolf Bjarne Kvinge rolf at xamarin.com
Wed Mar 7 11:02:53 UTC 2012


Hi,

Jason is right, you can't use delegates (Source in your case) and events at
the same time (because events are implemented using the Source delegate).

Rolf

On Wed, Mar 7, 2012 at 1:27 AM, Jason Awbrey <jason at awbrey.net> wrote:

> someone else can probably explain this better, but the general rule is
> that you can either assign a delegate to a class, or you can use C# style
> event handlers, but you can't do both.  I think in this case you are trying
> to do both - the UITableViewSource is a combined datasource/delegate.
>
> I imagine that when you assign a C# event handler, MT is creating a
> delegate for you under the covers, which clears out the delegate that you
> had manually assigned.
>
>
> On Tue, Mar 6, 2012 at 6:19 PM, victoria <iminurbase at hotmail.com> wrote:
>
>> 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.
>> _______________________________________________
>> MonoTouch mailing list
>> MonoTouch at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monotouch/attachments/20120307/2662a934/attachment.html>


More information about the MonoTouch mailing list