UITableView

繼承自UIScrollVIew 所以支持滾動
遵守協議 和 設置數據源

經常問的: 性能優化 創建的cell 很少個數有限
1. 通過標識去緩存池尋找可循環利用的cell
2. 如果找不到,創建一個新的cell,並給cell一個標識
3. 給cell設置新的數據 

汽車品牌 以及改進的 LOL英雄

// 讓自動把字典裏的數據 轉 模型
[self setValuesForKeysWithDictionary:dict];
// 隱藏狀態欄
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
/** 設置有多少組 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.carGroups.count;
//    return 2;
}
/** 第section組一共有多少行 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // 取得第section組 的對應模型
    JTCarGroup *cg = self.carGroups[section];
    return cg.cars.count;
   
}

/** 顯示哪一行的數據 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
     // 取得indexPath.section組對應的 模型
    JTCarGroup *cg = self.carGroups[indexPath.section];
    // 取得indexPath.row行對應的 名稱
    NSString *car = cg.cars[indexPath.row];
    // 設置cell顯示的文字
    cell.textLabel.text = car;

    return cell;
}
/** 顯示標題 */
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    JTCarGroup *cg = self.carGroups[section];
    return cg.title;
}
/** 顯示底部描述 */
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    JTCarGroup *cg = self.carGroups[section];
    return cg.desc;
}
/** 右邊的索引條顯示的字符串數據 */
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSArray *groups = [self.groups valueForKeyPath:@"title"];
    return groups;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章