Я создал файл JSON и отобразил его внутри tableViewController.Все должно быть в моем собственном цвете.
Вот изображение: https://www.imagebanana.com/s/1203/xWWzUNMs.html
Моя проблема: я не могу изменить цвет с черного текста.
МойВторая проблема: когда я прокручиваю вниз, черный текст находится внутри моих заголовков.Есть ли какие-либо изменения, чтобы исправить положение из текста?
Я пробовал много вещей, но я застрял.
Это мой код (tableViewController):
import UIKit
class CategoryTableViewController: UITableViewController {
@IBOutlet weak var searchBarAnswer: UISearchBar!
var categoryNumber: Int?
var answers: [Dictionary<String, AnyObject>]?
var answersSearchResult: [Dictionary<String, AnyObject>]?
var arrayQuestions: [Dictionary<String, AnyObject>]?
var sectionTitle: String?
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedSectionHeaderHeight = 80
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
if let path = Bundle.main.path(forResource: "data", ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
if let jsonResult = jsonResult as? Dictionary<String, AnyObject>, let questions = jsonResult["questions"] as? [Dictionary<String, AnyObject>] {
arrayQuestions = questions;
for question in questions {
if let id = question["id"] as? Int {
if(categoryNumber! == id)
{
answers = question["answers"] as? [Dictionary<String, AnyObject>]
sectionTitle = question["title"] as? String
}
}
}
answersSearchResult = answers;
}
} catch {
// handle error
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.width, height: 100))
let label = UILabel()
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.frame = CGRect.init(x: 5, y: 5, width: headerView.frame.width-10, height: headerView.frame.height-10)
label.text = sectionTitle
headerView.addSubview(label)
return headerView
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.answersSearchResult?.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! CategoryTableViewCell
let answer = answersSearchResult![indexPath.row]
cell.categoryLabel.text = answer["title"] as? String
let type = answer["type"] as! String
if(type == "question") {
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
searchBarAnswer.resignFirstResponder()
let answer = answersSearchResult![indexPath.row]
let type = answer["type"] as! String
if(type == "question") {
let link = answer["link"] as! Int
if let viewController2 = self.storyboard?.instantiateViewController(withIdentifier: "CategoryTableViewController") {
let categoryTableViewController = viewController2 as! CategoryTableViewController
categoryTableViewController.categoryNumber = link
self.navigationController?.pushViewController(viewController2, animated: true)
}
} else {
let link = answer["link"] as! String
if let viewController2 = self.storyboard?.instantiateViewController(withIdentifier: "PDFViewController") {
let pdfViewController = viewController2 as! PDFViewController
pdfViewController.pdfName = link
self.navigationController?.pushViewController(viewController2, animated: true)
}
}
}
А это моя таблица ViewCell:
import UIKit
class CategoryTableViewCell: UITableViewCell {
@IBOutlet weak var categoryLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}