InObjective-cHow to UseProtocolIs the content to be introduced in this article. It mainly introducesProtocolThis article introduces some concepts and operations of the Protocol. Let's take a look at the details first.
I. Protocol definition
- @protocol test
-
- -void) testpocol:int)t;
- @end
Ii. Protocol inheritance
H header file
- # Import "test. h" import Protocol
- @ Interface testViewController: UIViewController <test> {
- // Id <test> testp;
- }
M implementation file
- @ Implementation testViewController
-
- -Void) viewDidLoad {
- [Super viewDidLoad];
- // Class that calls the implementation method
- Testdiaoyong * td = [[testdiaoyong alloc] init];
Td. testd = self; assign the Class Object of the current implementation protocol to the desired place
- // You can also use the following method to transfer the Protocol
- [Td setpoco: self]
- }
-
- -(Void) testpocol :( int) s {
- NSLog (@ "testpocol... % d", s );
- }
- @ End
-
- Iii. Call Protocol
-
- @ Interface testdiaoyong: NSObject {
- Id <test> testp;
- }
-
- -(Void) setpoco: t;
-
- -(Void) setlen;
- @ End
-
- @ Implementation testdiaoyong
- @ Synthesize testp;
-
- // Protocol t can bear the type
-
- -(Void) setpoco: t {
- Self. testp = t;
- }
-
- -(Void) start {
- [Testp testpocol: 99];
- }
- @ End
Summary: InObjective-cHow to UseProtocolI hope this article will help you.