Saturday, January 11, 2014

Will IOS how to achieve like C # events

Tried delegate and NSNotificationCenter, can not achieve the desired effect.
Want to achieve this effect:
1 There is a class parent.m, class, there are methods update ();
3 defines a method viewUpdate () in another class view.m in;
The desired effect is () method is called viewUpdate () method in the parent class view.m class parent.m the update.

Callbacks way, if it is C # can be achieved:
1 event in the parent class is defined in the event
parent.m2 then view.m this event and class registration bind viewUpdate () method
event + = viewUpdate ();
3 Finally
in the parent class parent.m the update () methodif (event = null!) event ();
You can successfully call viewUpdate () method.

Younger beginner IOS, IOS does not know how to achieve a similar effect, her brother gets advice ~ ~
Reply:
http://blog.csdn.net/huifeidexin_1/article/details/7567731
Reply:
cited a floor xxo1986cxm reply:
http://blog.csdn.net/huifeidexin_1/article/details/7567731


I ask if I'm in a class instance multiple nsobject
Then execute multiple nsobject nsobject.delegate = self;
Then how this class method when executed judgment belongs nsobject?
Reply:
reference to the second floor Kellen_He reply:
Quote: references to a floor xxo1986cxm reply:

http://blog.csdn.net/huifeidexin_1/article/details/7567731


I ask if I'm in a class instance multiple nsobject
Then execute multiple nsobject nsobject.delegate = self;
Then how this class method when executed judgment belongs nsobject?


Many methods are generally custom tag, or an attribute used to distinguish
Reply:
And c # button click event which is almost the same as btn_click (object sender, EventArgs e) The sender is the button
delegate aspects which can bring the nsobject, tableView like this
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
Reply:
delegate and NSNotificationCenter should be able to achieve.
Interactive process between data objects, the object itself is nothing more than assumed two roles, the sender of data (sender), and the recipient of the data (receiver). Sender defines the recipient needs to follow protocol (protocol). Reception The sender needs to implement the protocol definition. Agreement is also a bridge between the two constraints.
there is a big difference between a delegate and NSNotificationCenter. How do according to their needs, choosing the right solution is a very critical issue. delegate concern is the close relationship between the two objects, and if so these two objects close relationship decoupling. NSNotificationCenter Notification Center observer mode is achieved. As long as the message is registered observer can receive messages sent.

No comments:

Post a Comment