Add title to UITableView programmatically using fast 2.2

I am trying to add a title to the table view, which is an NSLocalized String . I tried to do it

  self.tableView.tableHeaderView = NSLocalizedString("title", comment : "") as? UIView 

But there was a message that "Cast from type String for an unrelated UIView type always fails." I also tried without type casting, and then there was an error: "Cannot convert the type" String "to the type UIView ". can anyone help me add this title to tableView ? Thank you in advance.

+5
source share
1 answer

You need to set the view not to a string.

You can set a label in the field of view and set this view in the table header.

 var view1: UIView = UIView.init(frame: CGRectMake(0, 0, 320, 600)); var label: UILabel = UILabel.init(frame: CGRectMake(0, 0, 320, 600)) view1.addSubview(label); self.tableView.tableHeaderView = view1; 
+5
source

Source: https://habr.com/ru/post/1245888/


All Articles