iOS Basics-Advanced View-uitableview--instances: App Management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.