The protocol usage in Objective-C learning document is described in this article, mainly to understand and learn about the Protocol problems in Objective-C. For details, refer to the content of this article.
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:Objective-CLearning documentProtocolThe content of the usage method has been introduced. I hope this article will help you!