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