• IOS tableView的基本使用


     tableView  Style:Plain(头部标题 向上移 不会消失)

    tableView  Style:Grouped(头部标题 向上移 会 消失)

    #import "ViewController.h"
    #import "carGroup.h"
    
    @interface ViewController ()<UITableViewDataSource>
    @property (weak, nonatomic) IBOutlet UITableView *tableView;
    
    @property(nonatomic,strong) NSArray *carGroups;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //设置数据源
        self.tableView.dataSource=self;
    }
    
    //隐藏状态栏
    -(BOOL)prefersStatusBarHidden
    {
        return  YES;
    }
    
    -(NSArray *)carGroups
    {
       if(_carGroups==nil)
       {
           //初始化
           //德系品牌
           carGroup *car1=[[carGroup alloc]init];
           car1.title=@"德系品牌";
           car1.desc=@"德系品牌很好";
           car1.cars=@[@"奥迪", @"宝马", @"奔驰",];
           //日系品牌
           carGroup *car2=[[carGroup alloc]init];
           car2.title=@"日系品牌";
           car2.desc=@"日系品牌很好sssss";
           car2.cars=@[@"本田", @"丰田"];
           //欧系品牌
           carGroup *car3=[[carGroup alloc]init];
           car3.title=@"欧系品牌";
           car3.desc=@"欧系品牌很好yyyyyy";
           car3.cars=@[@"法拉力", @"兰博基尼",];
           _carGroups=@[car1,car2,car3];
       }
        return _carGroups;
    }
    
    /**一共有多少组数据*/
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        
        return self.carGroups.count;
    }
    
    /**第section组有多少行*/
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        //取得第section级对应的模型
        carGroup *cg=self.carGroups[section];
        return cg.cars.count;
    }
    
    /**每一行显示怎样的内容(cell)*/
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    //    UITableViewCell *cell=[[UITableViewCell alloc]initwithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        
        UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        
        //取出 模型indexpath.section组对应的模型
        carGroup *cg=self.carGroups[indexPath.section];
        //取车第indexpath.row这行对应的品牌名称
        NSString *car=cg.cars[indexPath.row];
        
        //设置cell显示的文字
        cell.textLabel.text=car;
        
        return cell;
    }
    
    /**第section组显示怎样的头部标题*/
    -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        carGroup *cg=self.carGroups[section];
        return cg.title;
    }
    /**第section组显示怎样的尾部标题*/
    -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
    {
        carGroup *cg=self.carGroups[section];
        return cg.desc;
    
    }
  • 相关阅读:
    Day10
    Day9
    Day8
    安装出错
    安装步骤
    技术面试
    工作机会查找
    selenium 关于富文本的处理
    selenium查找动态的iframe的name
    eclipse项目debug方法
  • 原文地址:https://www.cnblogs.com/liuwj/p/6432096.html
Copyright © 2020-2023  润新知