创建UITableViewCell(不使用XIB情况)

来源:互联网 发布:利用网络宣传党史 编辑:程序博客网 时间:2024/05/21 19:50
一、直接使用系统提供的cell    //1. 从复用池(复用队列)中根据复用标识取一个cell    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"cell];    //2. 如果取不到,则创建一个cell并指定一个复用标识。    if (cell == nil)   {        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: @"cell];    }二、使用自己定义的cell    [_myTableView registerClass:[myCell class] forCellReuseIdentifier:@"cell"];    myCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];    然后在myCell里面自定义需要的控件,注意控件需要在cell初始化时添加到contentView。(注意:自定义cell,初始化不是init,而是initWithStyle)
0 0