1.UItTableViewController
標示圖控制器
兩種單元格類型
UITableViewCellStyleDefault 不支持子標題
UITableViewCellStyleSubtitle 支持子標題
都支持圖片與主題
另外兩種單元格類型
UITableViewCellStyleValue1
UITableViewCellStyleValue2
都不支持 圖片
--------------------------定製單元格------------------------
1.通過UITableViewCell的contentView屬性添加子視圖
static NSString *identifier = @"firstId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]autorelease];
/*
不會改變的內容放在括號的裏面去寫
*/
//創建子視圖
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(200, 0, 100, 44)];
label.tag = 123;
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
/*
會改變的內容放在括號的外面面去寫
*/
NSDictionary *dic = [_newsList objectAtIndex:indexPath.row];
//獲取時間的文本
UILabel *timeLabel = (UILabel *)[cell.contentView viewWithTag:123];
timeLabel.text = [NSString stringWithFormat:@"%@小時之前",dic[@"time"]];
cell.textLabel.text = dic[@"title"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@條評論",[dic objectForKey:@"commentCount"]];
2.使用xib自定義視圖,佈局十分方便,開發較爲迅速
if (cell == nil) {
//同xib文件創建的
/*
用xib文件創建的時候
一定要把UITableViewCell 的identifier屬性手動的設置上
*/
cell = [[[NSBundle mainBundle]loadNibNamed:@"SecondCell" owner:self options:nil]lastObject];
}
獲取工程主路徑 加載xib 選擇視圖
3.子類化UITableViewCell,更加面向對象
- (void)_initViews
{
//創建標題文本
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = [UIFont boldSystemFontOfSize:14];
_titleLabel.textColor = [UIColor orangeColor];
[self.contentView addSubview:_titleLabel];
//其他視圖
}
- (void)layoutSubviews
{
//必須寫的**********
[super layoutSubviews];
//進行佈局
_titleLabel.frame = CGRectMake(10, 5, 200, 20);
_titleLabel.text = [self.dic objectForKey:@"title"];
//其他
}
定製單元格
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
【ios 彙總 你可能不知道的調試技巧】
听着rap写代码
2020-02-20 22:14:16
textFiled要注意的地方
moon_shine
2020-06-24 18:40:42
AWS S3服務
阿飞小伙子_blogs
2020-06-04 13:28:05
UIScrollView頻道滑動(授人以魚,不如授人以漁)
hherima
2020-02-21 23:59:46
SDWebImage源碼解析
阿飞小伙子_blogs
2019-06-22 01:56:17
【精】iOS知識樹,知識點(包括對象、Block、消息轉發、GCD、運行時、runloop、動畫、Push、KVO、tableview,UIViewController、提交AppStore)
hherima
2018-09-04 22:03:01
IOS 開發,調用打電話,發短信,打開網址
moon_shine
2018-08-31 21:25:18
iOS系統架構和常用框架
陈荣科
2018-08-31 01:08:49
ios 內購服務器驗票(漏單處理)
听着rap写代码
2018-08-28 22:52:36
UIScrollView的基本用法
逝华_浮梦
2018-08-28 06:52:14