之前写的有不少人反应不好用,现在更新一个我常用的方法,有兴趣的可以试试。采用的是注册的方式。
//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;
}
网友评论