0

I am having an issue with UITableViewCell. When the table view loads, some of the cell does not have subtitle. I aldy set the style of cell to subtitle. The weird part is when I scroll up and down, the missing parts appear again but some other cells are missing table subtitle. Here is my code for the cellForRowAtIndexPath

let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! UITableViewCell
    cell.layoutMargins = UIEdgeInsetsZero
    cell.preservesSuperviewLayoutMargins = false
    let poList = self.PoList[indexPath.row]
    if(poList.POShort == "header"){
        cell.backgroundColor = SharedClass().coopGroupHeaderColor
        let selectedColor = UIView()
        selectedColor.backgroundColor = SharedClass().coopGroupHeaderColor
        cell.selectedBackgroundView = selectedColor
        cell.textLabel?.textColor = UIColor.blackColor()
        cell.textLabel?.font = UIFont.boldSystemFontOfSize(18.0)
        cell.textLabel?.textAlignment = .Left
        cell.accessoryType = .None
        let t_header = "Program Office"
        cell.textLabel?.text = t_header
        cell.detailTextLabel?.text = ""
        cell.userInteractionEnabled = false;
    }
    else{
        cell.backgroundColor = indexPath.row % 2 == 0 ? UIColor.clearColor() : SharedClass().cellBackGroundColor
        let selectedColor = UIView()
        selectedColor.backgroundColor = SharedClass().selectedCellColor
        cell.selectedBackgroundView = selectedColor
        cell.textLabel?.font = UIFont.boldSystemFontOfSize(11.0)
        cell.textLabel?.textColor = UIColor.blackColor()
        if(poList.POShort != "OTHER" && poList.POShort != "invalid" && poList.POShort != "all"){
            cell.textLabel?.text = poList.POName + " - " + poList.POShort
        }
        else{
            cell.textLabel?.text = poList.POName
        }
        let cellValue = "Total number of staff not responded - " + poList.totalUsers
        cell.detailTextLabel?.text = cellValue
        if(poList.totalUsers == "0"){
            cell.userInteractionEnabled = false;
            cell.accessoryType = .None
        }
        else{
            cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
        }
    }


    return cell

and as a result, this cells missing subtitle will not perform push segue either.

Please help.

Thank you.

Jun Luo
  • 139
  • 1
  • 13

1 Answers1

0

May be the issue is - you are not setting any value in the following if statement:

if(poList.POShort == "header"){
     ......
    .......
    cell.detailTextLabel?.text = ""   <<<<<<<<
    ......
Tushar
  • 3,022
  • 2
  • 26
  • 26
  • Thank you. It works. But then the title will look weird cuz there's a second line there with nothing and the text is not vertical centered – Jun Luo Jun 04 '15 at 13:11
  • hmm, you should try creating a custom cell i.e UITableViewCell subclass with your own design of the cell elements. There are many examples out there in can search. – Tushar Jun 05 '15 at 06:27
  • Thank you very much. I will check them. – Jun Luo Jun 05 '15 at 12:24