self.mArr = [UIFont familyNames];
//創建初始化表視圖
self.mTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
UIView *pView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
pView.backgroundColor = [UIColor blueColor];
self.mTableView.tableHeaderView = pView;
//設置頁眉高度
self.mTableView.sectionHeaderHeight = 50;
//設置委托對象
self.mTableView.dataSource = self;
self.mTableView.delegate = self;
//加到視圖當中
[self.view addSubview:self.mTableView];
#pragma mark --- tableView DataSource----
//每個分段中的行數
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.mArr count];
}
//每行的繪制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifer = @"identfier";
UITableViewCell *pCell = [tableView dequeueReusableCellWithIdentifier:identifer];
if (nil == pCell)
{
pCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifer];
}
//獲取當前行
NSUInteger cellRow = [indexPath row];
//根據行數找到數組中對應下標的數據
NSString *pTempStr = [self.mArr objectAtIndex:cellRow];
//設置文本內容
pCell.textLabel.text = pTempStr;
//設置文本字體
pCell.textLabel.font = [UIFont fontWithName:pTempStr size:18];
pCell.detailTextLabel.text = @“detailText";
//在左側添加圖片
pCell.imageView.image = [UIImage imageNamed:@"Default-568h@2x"];
pCell.accessoryType = UITableViewCellAccessoryCheckmark;
return pCell;
}
//創建表頭
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"I'm Header_Title";
}
//創建表尾
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return @"I'm Footer_Title";
}
#pragma mark---table delegate-----
//選中某一行會調用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *pStr = [NSString stringWithFormat:@"你選中了第%d行",row];
//模態視圖
UIActionSheet *pActionSheet = [[UIActionSheet alloc]initWithTitle:@"ActionSheet" delegate:self cancelButtonTitle:@"確認" destructiveButtonTitle:pStr otherButtonTitles:nil, nil];
[pActionSheet showInView:self.view];
//選中行逐漸淡出
[self.mTableView deselectRowAtIndexPath:indexPath animated:YES];
}
//調整行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
//調整header 高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20;
}
//行內容進行偏移
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 0;
}