Instead of using xib, we use the default dynamic cell in storyboard to describe the custom cell
First, load the cell in the third data source method
{
Mjappcell *cell = [TableView dequeuereusablecellwithidentifier:@ "app"];
The set method is called when the model data is passed to the cell, and the data and state of the button are overwritten in the set method.
Cell.app = Self.apps[indexpath.row];
return cell;
}
PS: A tableview can back up multiple types of cells, then only need to load the cell according to different identities
Second, add the Model data property in MJAppCell.h and override the Set method
The Mjapp is ready to be dragged directly, with the app's icon,name,size in it,
The Download property.
@property (Nonatomic,strong) Mjapp *app;
Assign these properties of the app to the appropriate control in the cell in the Set method.
-(void) Setapp: (Mjapp *) app
{
_app = app;
Self.iconView.image = [UIImage ImageNamed:app.icon];
Self.nameView.text = App.name;
Self.introView.text = [NSString stringwithformat:@ "Size:%@ | Download Volume:%
@ ", app.size,app.download];
}
Three, click the Download button to display the downloaded, and the button can no longer be clicked
1. Set the text at disabled to downloaded
2. Add an attribute
to the Mjapp model (nonatomic,assign, Getter = isdownloaded) BOOL downloaded;
3. Listen to the download button and implement the method
//Click the download button
-(ibaction) Downloadclick: (UIButton *) btn{
//Make the button invalid
self.app.downloaded = YES;
btn.enabled = NO;
2. Notification Agent
}
4. Get the download button (Outlet) to overwrite the state of the button in the Set method
-(void) Setapp: (Mjapp *) app
{
......
Overwrite the state of the button
self.downloadView.enabled = (self.app.isDownloaded = = NO);
}
5. Add a prompt to download successfully
1> Definition Protocol
@protocol mjappcelldelegate <NSObject>
@optional
-(void) APPCELLDIDCLICKEDDOWNLOADBTN: (Mjappcell *) cell;
@end
2> Compliance Agreement
@property (Nonatomic,weak) id<mjappcelldelegate> delegate;
3> Notification of the agent button was clicked in the method of downloading the button
-(Ibaction) Downloadclick: (UIButton *) btn{
....
2. Notification Agent
if ([Self.delegate respondstoselector: @selector
(appcelldidclickeddownloadbtn:)]) {
[Self.delegate appcelldidclickeddownloadbtn:self];
}
}
4> set the controller as a proxy in the third data source method and let the controller follow the proxy protocol
5> implementing the Proxy method of cell
PS: When do you use an agent?
When something happens inside a view, you want to tell the controller
iOS Basics-Advanced View-uitableview--instances: App Management