Here is an example of the relationship between Uitableviewcontroller and UITableView:
//------------------------------------------------------------------------//UITableViewController.h@interfaceUitableviewcontroller:uiviewcontroller <uitableviewdelegate, uitableviewdatasource>@property (nonatomic,retain) UITableView*TableView;@end//------------------------------------------------------------------------//UITableView.h@protocolUitableviewdatasource;@protocolUitableviewdelegate<nsobject, uiscrollviewdelegate>@optional//The delegate method is optional@end@interfaceUitableview:uiscrollview <NSCoding>@property (nonatomic, assign)ID<UITableViewDataSource>DataSource, @property (nonatomic, assign)ID<UITableViewDelegate>Delegate;@end@protocolUitableviewdatasource<nsobject>@required//DataSource methods that must be implemented@optional//Optional DataSource method@end
1. Uitableviewcontroller implements Uitableviewdelegate and Uitableviewdatasource two protocols
2. These two protocols are defined in the UITableView
Note: You can add <nsobject> to the definition, which means that the method in the parent agreement is also implemented
3. After the protocol is defined, you can declare two properties to place its delegate object: DataSource and delegate
Note: If the definition of the protocol is placed after the attribute declaration, then in advance to declare the next protocol, such as @protocol Uitableviewdatasource;
The order of the above code is exactly according to the library file, I do not know why delegate definition before, DataSource defined in the maybe is to show the next two forms (I guess ~)
Note: These two properties are assign, in other words, weak non-strong, because Uitableviewcontroller has a property UITableView (the former owns the latter), and UITableView delegates and data sources point to Uitableviewcontroller, if set to Stong, will be owned by each other, introducing retain cycle (retaining ring)
4, the method of implementing the delegate object is to declare a class to obey the trust protocol, and then implement the method in the protocol in the class.
Protocol (protocol), Delegate (delegate), DataSource (data source)