Button in ContentView causes crash in MonoTouch runtime. Bug in Monotouch 4.0?

后端 未结 1 774
猫巷女王i
猫巷女王i 2021-01-14 05:12

My application worked fine in MT 3.0. Now when I upgraded. I am seeing errors when a button is in a ContentView. Crashes happen when the button is clicked. Code:

<         


        
1条回答
  •  别那么骄傲
    2021-01-14 05:33

    Not sure if this is the problem, but when I upgraded to 4.0, I also got some random crashes. It turned out that the 4.0 GC is more aggressive, and that things I was previously getting away with were no longer kosher.

    In particular, if I had a event handler assigned to a button, I needed to be sure the button was declared at the class level. If it was declared locally in the method, the GC would purge the reference when it went out of scope, and then later when the event handler tried to fire, it's reference was no longer there.

    So try moving the declaration of your button outside of your method.

    0 讨论(0)
提交回复
热议问题