美文网首页
iOS之TableViewCell重用机制避免重复显示问题(注册

iOS之TableViewCell重用机制避免重复显示问题(注册

作者: 楠Acer | 来源:发表于2015-12-11 10:27 被阅读2527次

之前写的有不少人反应不好用,现在更新一个我常用的方法,有兴趣的可以试试。采用的是注册的方式。

//viewDidLoad中

-(void)createTableView

{

UITableView*tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,kMainScreenWidth,kMainScreenHeight)style:UITableViewStyleGrouped];

tableView.delegate=self;

tableView.dataSource=self;

tableView.showsVerticalScrollIndicator=NO;

tableView.showsHorizontalScrollIndicator=NO;

tableView.backgroundColor= [UIColorcolorWithHexString:@"#F2F2F2"];

tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;

tableView.mj_header= [MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(_loadNewData)];

[self.viewaddSubview:tableView];

[tableViewregisterNib:[UINibnibWithNibName:@"ZKMessageTableViewCell"bundle:nil]forCellReuseIdentifier:@"ZKMessageTableViewCell"];

}

//只写一个关键的cellForRow方法,其他的方法都一样写法。

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

ZKMessageTableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:@"ZKMessageTableViewCell"];

return cell;

}

相关文章

网友评论

      本文标题:iOS之TableViewCell重用机制避免重复显示问题(注册

      本文链接:https://www.haomeiwen.com/subject/rieyhttx.html