標籤: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的基本使用