A few days ago, the blog, customized a Portfolio view, because of the C # event mechanism does not understand, so the View button callback controller way I chose to develop Android often used interface callback. After my colleague pointed out the problem, I looked up some information and read some information about the C # entrustment mechanism in several books. Finally encapsulates the delegate event bus, Java is slowly imitating this delegation mechanism.
The encapsulated classes and how to use them are posted below.
The class that encapsulates the delegated mechanism first:
Using System;
Namespace Ruilaigrow.ios
{
///<summary>
///Delegate Event bus base class
///by GE
///</summary>
public class Eventbus:eventargs
{public
Eventbus (string bus)
{this
. Bus = bus;
}
public string Bus {get; set;}
}
public class Eventbusdealer {public
event eventhandler<eventbus> Newbusinfo;
public void Newbus (object sender, String bus) {
raisenewbusinfo (sender, bus);
protected void Raisenewbusinfo (object sender, String bus)
{
eventhandler<eventbus> newbusinfo = Newbusinfo;
if (newbusinfo!= null) {
newbusinfo (sender, New Eventbus (bus));}}}
In the post use method, for example, the scene: If now in my custom view has a button, in his click event callback to the interface of a few data.
The first step is to instantiate the encapsulated words in a custom view to delegate event objects:
Delegate event public
Eventbusdealer Eventbus = new Eventbusdealer ();
In the Click event:
Button.touchupinside + = (sender, e) =>
{
eventbus.newbus (_list[index], "");
Use view in the interface controller to find the object of the delegate event and bind the event:
ListView.eventBus.NewBusInfo + = (object sender, Eventbus e) => {
//event sent here
};
The Eventbus I encapsulated above (Android I have been using is eventbus, so from the perspective of the feelings of this, do not mislead people. I write my own iOS demo, the program's icon has been using Android's small robot icon, haha ha) sent the second parameter is string, you can modify to achieve their own needs.