R.Ham
R.Ham

Reputation: 67

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].

Upvotes: 2

Views: 1175

Answers (1)

Özgür Ersil
Özgür Ersil

Reputation: 7013

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
}

Upvotes: 1

Related Questions