2015-11-10 MVC

Source: Internet
Author: User
Tags uikit

Custom cell

TechNewsCell.h

#import <UIKit/UIKit.h>
@class Techmodel;


@interface Technewscell:uitableviewcell
@property (nonatomic, strong) Techmodel *techmodel;
/** provides a class method that allows you to quickly create a Cell */
+ (Instancetype) Cellwithtableview: (UITableView *) TableView;
@end

technewscell.m

#import "TechNewsCell.h"
#import "TechModel.h"
#import "Uiimageview+webcache.h"

@interface Technewscell ()
@property (Weak, nonatomic) Iboutlet UILabel *titlelabel;
@property (Weak, nonatomic) Iboutlet UILabel *timelabel;
@property (Weak, nonatomic) Iboutlet Uiimageview *picimage;
@end

@implementation Technewscell
+ (Instancetype) Cellwithtableview: (UITableView *) TableView
{
1. Reusable identifiers
static NSString *id = @ "Cell";
2. TableView Querying reusable cells
Technewscell *cell = [TableView dequeuereusablecellwithidentifier:id];

3. If you do not have a reusable cell
if (cell = = nil) {
NSLog (@ "Load xib");
Load a custom view from Xib
cell = [[[NSBundle Mainbundle] loadnibnamed:@ "Technewscell" Owner:nil Options:nil] lastobject];
}
return cell;
}

-(void) Settechmodel: (Techmodel *) Techmodel
{
_techmodel = Techmodel;
Self.timeLabel.text = Techmodel.time;
Self.titleLabel.text = Techmodel.title;
[Self.picimage Sd_setimagewithurl:[nsurl URLWITHSTRING:TECHMODEL.PICURL];
}

Model class

#import <Foundation/Foundation.h>
@interface Techmodel:nsobject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *time;
@property (nonatomic, copy) NSString *picurl;
@property (nonatomic, copy) NSString *url;
@end

Controller controllers

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {
return self.techNewsArray.count;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {
Technewscell *cell = [Technewscell Cellwithtableview:tableview];
Cell.techmodel = Self.technewsarray[indexpath.row];
return cell;
}

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath
{
return 110;
}

2015-11-10 MVC

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.