iOS: how to dequeue reusable ‘default’ cells without actually having a cell in storyboard

If you don’t have any prototype cell in your storyboard, you can use the dequeueReusableCellWithIdentifier: api to create classic cell

UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
   cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

swift:

var cell : UITableViewCell!
cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
if cell == nil {
    cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)
}

Leave a Comment