UITableViewController (用.xib文件自定义cell)

来源:互联网 发布:Mac版本好玩的网络游戏 编辑:程序博客网 时间:2024/05/16 17:06

说明:

这个控件继承于UIViewController,而且里面自带了UITableView,不像其它控件,还需要添加一个需要显示的视图。

//高度属性的设置:self.tableView.rowHeight = 80;  //所有列的高度都是80  第二种方法:用代理方法heightForRowAtIndexPath根据某一列返回指定的高度。//0.定义循环标记static NSString* CellIdentifier = @"Cell";//1,从缓存池中取出CellUITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];//2,缓存池中没有Cellif(cell == nil){    NSArray* objects = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:nil options:nil];    //或者 UINib* nib = [UINib ninWithNibName:@"NewCell" bundle:nil];//     NSArray* objects = [nib instantiateWithOwner:nil options:nil];cell = objects[0];}//3,取出新闻模型News* news = _news[indexPath.row];//4,新闻标题和新闻图片UILabel* titleLabel = (UILabel*)[cell viewWithTag:1];titleLabel.text = news.title;UIImageView* imageView = (UIImageView*)[cell viewWithTag:4];imageView.image = [UIImage imageNamed:news.icon];return cell;




0 0
原创粉丝点击