IOS tableView的基本使用

來源:互聯網
上載者:User

標籤:usb   ons   rss   exp   使用   text   ble   eid   基本使用   

 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[email protected][@"奧迪", @"寶馬", @"平治",];       //日系品牌       carGroup *car2=[[carGroup alloc]init];       car2.title=@"日系品牌";       car2.desc=@"日系品牌很好sssss";       car2.cars[email protected][@"本田", @"豐田"];       //歐系品牌       carGroup *car3=[[carGroup alloc]init];       car3.title=@"歐系品牌";       car3.desc=@"歐系品牌很好yyyyyy";       car3.cars[email protected][@"法拉力", @"蘭博基尼",];       [email protected][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;}

 

IOS tableView的基本使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.