iOS---tableView的一些内容


#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所在的tabbarcontrollertabbar会自动隐藏

    // test1控制器被pop的时候,test1所在的tabbarcontrollertabbar会自动显示


    

    [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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值