R.Ham R.Ham - 2 months ago 17
iOS Question

Swift: How to access a label in a custom cell within a certain tableView section

I have a custom

UITableViewCell
with a
UILabel
called
CellLabel
. I want to be able to access this label at a certain
tableView section
e.g. section 3 and provide it a string to display without the use of an array and
arrayName[indexPath.section]
.

Answer

You can catch it in cellForRowAtIndexPath override of a TableView

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("YourCustomCellRegisterName") as YourCustomCell
    if(indexPath.section == 3){
       cell.CellLabel.text = "foo"
    }
    return cell
}