iOS中的应用启动原理以及嵌套模型开发示例详解

2020-01-14 18:34:33于海丽

    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    //4.3设置cell的数据
    //设置对应的组
    YYcarsgroup *carsgroup=self.car[indexPath.section];
    //设置对应的行
    YYcars *yycars=carsgroup.cars[indexPath.row];

    cell.imageView.image=[UIImage imageNamed:yycars.icon];
    cell.textLabel.text=yycars.name;
    //4.4返回cell
    return cell;
}

//设置每组的标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    YYcarsgroup *carsgroup=self.car[section];
    return carsgroup.title;
}

//设置索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    //利用kvc取出所有的标题
    NSArray *title=[self.car  valueForKeyPath:@"title"];
    return title;
}

//隐藏状态栏
-(BOOL)prefersStatusBarHidden
{
    return  YES;
}
@end


实现效果:

 

iOS中的应用启动原理以及嵌套模型开发示例详解

三、注意点

1.设置索引

代码如下:

复制代码
//设置索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    //利用kvc取出所有的标题
    NSArray *title=[self.car  valueForKeyPath:@"title"];