Model class
Commentsmodel
"JSONModel.h""getCommentData.h"@interface Commentsmodel:jsonmodel@property ( nonatomic,copy) nsarray<getcommentdata> *commentlist; @end
"commentsModel.h"@implementation commentsmodel@end
Getcommentdata
"JSONModel.h"@protocol getcommentdata@end@interface getcommentdata: Jsonmodel@property (nonatomic,copy) NSString *message; @property (nonatomic,copy) NSString *nickname;@ Property (nonatomic,copy) NSString *createtimestr; @end
"getCommentData.h"@implementation getcommentdata@end
Controller
#import"CommentsTableViewController.h"#import"CommentsModel.h"#import"CommentCell.h"@interfaceCommentstableviewcontroller () @property (nonatomic,strong) Nsarray *Commentsarray;@end@implementationcommentstableviewcontroller-(Nsarray *) commentsarray{if (_commentsarray==Nil) {NSData *data=[nsdata datawithcontentsoffile:[[nsbundle Mainbundle] Pathforresource:@"Comment_list.json"Oftype:nil]]; Commentsmodel *commensm=[[Commentsmodel Alloc]initwithdata:data Error:nil]; _commentsarray=Commensm.commentlist; }Return_commentsarray;} - (void) Viewdidload {[Super viewdidload];} - (void) didreceivememorywarning {[Super didreceivememorywarning];//Dispose of any resources the can be recreated.}#pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {Return1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {ReturnSelf.commentsArray.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Static NSString *id=@"Comment"; Commentcell *cell=[TableView Dequeuereusablecellwithidentifier:id];if (cell==Nil) {cell=[[Commentcell Alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:id]; } cell.commentdata=Self.commentsarray[indexpath.row];ReturnCell;} -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{ return [self Cellheightforindexpath:indexpath cellcontentviewwidth:[self Cellcontentviewwith]];} -(cgfloat) cellcontentviewwith{cgfloat width=[UIScreen mainscreen].bounds.size.width; if ([uiapplication sharedapplication].statusbarorientation! = uiinterfaceorientationportrait && [[ Uidevice currentdevice].systemversion Floatvalue] < 8) {width = [UIScreen mainscreen]. Bounds.size.height; } return width;} @end
Code for the specific custom cell
#import <UIKit/UIKit.h>@class getcommentdata; @interface Commentcell:uitableviewcell@property (nonatomic,strong) getcommentdata *commentdata; @property ( Nonatomic,strong) UILabel *Namelabel; @property (nonatomic,strong) UILabel *Titlelabel; @property (Nonatomic, Strong) UILabel *Datelabel; @end
#import"CommentCell.h"#import"CommentsModel.h"@implementationcommentcell-(void) Setcommentdata: (Getcommentdata *) commentdata{_commentdata=Commentdata; _titlelabel.text=Commentdata.message; _datelabel.text=COMMENTDATA.CREATETIMESTR; _namelabel.text=Commentdata.nickname;} -(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{self =[Super Initwithstyle:style Reuseidentifier:reuseidentifier];If(self) {[Self setup];}ReturnSelf;} -(void) setup{_namelabel=[uilabelNew]; [Self.contentview Addsubview:_namelabel]; _namelabel.textcolor=[uicolor colorwithred:0.891 Green:0.549 Blue:0.073 Alpha:1.000]; _namelabel.font=[uifont systemfontofsize:15]; _namelabel.numberoflines=1; _titlelabel=[uilabelNew]; [Self.contentview Addsubview:_titlelabel]; _titlelabel.textcolor=[Uicolor Darkgraycolor]; _titlelabel.font=[uifont systemfontofsize:15]; _titlelabel.numberoflines=0; _datelabel=[uilabelNew]; [Self.contentview Addsubview:_datelabel]; _datelabel.textcolor=[uicolor colorwithred:0.679 Green:0.166 Blue:0.828 Alpha:1.000]; _datelabel.font=[uifont systemfontofsize:15]; _datelabel.numberoflines=1; CGFloat margin=10; UIView *contentview=Self.contentview; _namelabel.sd_layout. Leftspacetoview (Contentview,margin). Topspacetoview (Contentview,margin). RightSpaceToView ( Contentview,margin). Heightis (20); _titlelabel.sd_layout. Leftspacetoview (Contentview,margin). Topspacetoview (_namelabel,205). Heightis (20150); [Self Setupautoheightwithbottomviewsarray:@[_titlelabel,_datelabel,_namelabel] bottommargin:margin];} -(voidvoid @end
iOS Graphics Mix