1

I am trying to make the title and the sectionData different sized, I would like title bold at least. I have been trying to find a solution but haven't found anything. Any help is greatly appreciated.

I have tried to use an using a function which returns a NSMutableAttributedString but this converts both the title and the sectionData to the font I choose. I called it in tableView(cellForRowAt) function as a replacement for the current cell.textLabel?.text.

Thank you very much!

struct cellData {
   var opened = Bool()
   var title = String()
   var sectionData = [String]()
}

class FAQTableViewController: UITableViewController {

var tableViewData = [cellData]()

override func viewDidLoad() {
    super.viewDidLoad()
    tableViewData = [cellData(opened: false, title: "How can I connect with my friends?", sectionData: ["Go to the friends page, click add friends and type in your friends phone number."])]
}

// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
    return tableViewData.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if tableViewData[section].opened == true{
        return tableViewData[section].sectionData.count + 1
    } else{
        return 1
    }
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let dataIndex = indexPath.row - 1
    if indexPath.row == 0{
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
        cell.textLabel?.text = tableViewData[indexPath.section].title
        return cell
        
    } else{
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return UITableViewCell()}
        cell.textLabel?.text = tableViewData[indexPath.section].sectionData[dataIndex]
        return cell
    }
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
    if indexPath.row == 0{
        if tableViewData[indexPath.section].opened == true {
            tableViewData[indexPath.section].opened = false
            let dataIndex = indexPath.row - 1
            if indexPath.row == 0{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return}
                cell.textLabel?.text = tableViewData[indexPath.section].title
                
            } else{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {return}
                cell.textLabel?.text = tableViewData[indexPath.section].sectionData[dataIndex]
            }
            let sections = IndexSet.init(integer: indexPath.section)
            tableView.reloadSections(sections, with: .none)
        } else{
            tableViewData[indexPath.section].opened = true
            let sections = IndexSet.init(integer: indexPath.section)
            tableView.reloadSections(sections, with: .none)
        }
    }
}

0 Answers0