#import "TableViewController.h"
@interface TableViewController () <UITableViewDataSource,UITableViewDelegate>
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title=@"标题";
//self.navigationController.navigationBar.tintColor = [UIColor blackColor];
// self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
//设置导航条的颜色(直接选颜色)
//self.navigationController.navigationBar.barTintColor =[UIColor orangeColor];
//set NavigationBar 背景颜色RGB格式
//设置导航条颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:255/255.0 green:130/255.0 blue:0/255.0 alpha:1.0]];
//设置tableView样式为分组
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
//把左侧按钮设成文字
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"导航条左侧按钮" style:0 target:self action:nil];
//颜色设置
self.navigationItem.rightBarButtonItem.tintColor=[UIColor whiteColor];
//set NavigationBar 背景颜色RGB格式
//设置导航栏右侧按钮为图片
self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(XiaoXi) image:@"main_activtiy_msg_normal44"];
//设置顶部间距最小
// self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//点击item之后执行的操作
- (void)XiaoXi
{
Test1ViewController *test1 = [[Test1ViewController alloc] init];
test1.title = @"test1";
[self.navigationController pushViewController:test1 animated:YES];
}
#pragma mark - 数据源
#pragma mark - 设置一共几组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 0;
}
#pragma mark - 每组几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
}
#pragma mark - 代理
#pragma mark - 每行显示什么
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//定义一个cell的标识
static NSString *ID = @"cell";
// 2.从缓存池中取出cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//设置cell不能点击
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// 3.如果缓存池中没有cell
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
// 4.设置cell的属性
cell.textLabel.text = [NSString stringWithFormat:@"test-message-%ld", indexPath.row];
// 设置 cell 右侧的样式
cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;
//右侧加个开关
UISwitch *switchView = [[UISwitch alloc] init];
[switchView setOn:YES];
cell.accessoryView = switchView;
//右侧加图片
UIImageView *img =[[UIImageView alloc]init];
img.frame=CGRectMake(100, 100, 100, 100);
img.image= [UIImage imageNamed:@"default_icon"];
cell.accessoryView =img;
return cell;
}
#pragma mark - 选中某行的点击操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
Test1ViewController *test1 = [[Test1ViewController alloc] init];
test1.hidesBottomBarWhenPushed = YES;
test1.title = @"测试1控制器";
// 当test1控制器被push的时候,test1所在的tabbarcontroller的tabbar会自动隐藏
// 当test1控制器被pop的时候,test1所在的tabbarcontroller的tabbar会自动显示
[self.navigationController pushViewController:test1 animated:YES];
}
#pragma mark - 返回每一行对应的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
#pragma mark - 标题头
#pragma mark - 标题尾
#pragma mark - 设置间距
#pragma mark - 指定这组与上一组的间距 可以自定义多个cell的间距
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if(section ==0) return 10;
return 5;
}
#pragma mark - 指定这组与下一组的间距
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 5;
}
#pragma mark - <#注释#>
#pragma mark - <#注释#>
#pragma mark - <#注释#>
@end