Accessing Delegates from Outside the Delegate
Can we access delegates(ListView) from outside a Delegate Declaration.Say i want to change a property like state of a Delegate.
For eg. in this sample code can i access a particular row delegate of list_view1 ?
model: myModel delegate:listDelegate }
thorbjorn last edited by
This is not possible in general since delegates are created on-demand (and thrown away at will when no longer necessary). So the delegate you are requesting may in fact not exist.
So you have to either expose the necessary properties to allow the delegate to react to that, or the delegate can call a method and pass itself as a parameter, then you know you can access the delegate through this parameter.
gustavo last edited by
I have a question about this solution:
Now, suppose I remove, from the model, the item associated with this delegate instance. Will the instance itself be deleted? Or will it be retained, since there's still a reference to it in myDelegate variable? In other words, the value in myDelegate will then be undefined?
yes the value in myDelegate will be undefined.A solution to this problem is to reset the variable in myDelegate to NULL whenever the list starts moving( onMovementStarted: ) just to make sure it doesn't point to an invalid object/delegate