ios初識UITableView及簡單用法二(模型資料)

來源:互聯網
上載者:User

標籤:esc   tom   資訊   model1   tin   顯示   copy   owa   logs   

////  ViewController.m//  ZQRTableViewTest////  Created by zzqqrr on 17/8/24.//  Copyright (c) 2017年 zzqqrr. All rights reserved.//#import "ViewController.h"#import "ZQRCarGroup.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;}- (NSArray *)carGroups{    if(_carGroups==nil){        ZQRCarGroup *model1=[[ZQRCarGroup alloc] init];        model1.title=@"哈哈";        model1.desc=@"呵呵";        model1.cars[email protected][@"第一組第一行"];                ZQRCarGroup *model2=[[ZQRCarGroup alloc] init];        model2.title=@"哈哈";        model2.desc=@"呵呵";        model2.cars[email protected][@"第二組第一行",@"第二組第二行"];        ZQRCarGroup *model3=[[ZQRCarGroup alloc] init];        model3.title=@"哈哈";        model3.desc=@"呵呵";        model3.cars[email protected][@"第三組第一行",@"第三組第二行",@"第三組第三行"];        _carGroups=@[model1,model2,model3];    }    return _carGroups;}/** 設定多少組組 */- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return self.carGroups.count;}/** 指定組中的行 */- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    ZQRCarGroup *group=self.carGroups[section];    return group.cars.count;}/** 每一組顯示的內容 */- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];    ZQRCarGroup *group=self.carGroups[indexPath.section];    NSString *strCar=group.cars[indexPath.row];    cell.textLabel.text=strCar;    return cell;}/** 頭部文字 */-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{    ZQRCarGroup *model=self.carGroups[section];    return model.title;}/** 尾部文字 */- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{    ZQRCarGroup *model=self.carGroups[section];    return model.desc;}@end

模型

////  ZQRCarGroup.h//  ////  Created by zzqqrr on 17/8/25.////#import <Foundation/Foundation.h>@interface ZQRCarGroup : NSObject/** *頭部標題 */@property (nonatomic,copy) NSString *title;/** *尾部的描述 */@property (nonatomic,copy) NSString *desc;/** *所有的資訊列表 */@property (nonatomic,strong) NSArray *cars;@end
////  ZQRCarGroup.m//  ////  Created by zzqqrr on 17/8/25.////#import "ZQRCarGroup.h"@interface ZQRCarGroup()@end@implementation ZQRCarGroup@end

 

ios初識UITableView及簡單用法二(模型資料)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.