Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to a static cell

I created a TableView directly in the storyboard; this tableView contains 8 static cells (style basic) in 4 section; now, how could I edit via code these cells? for example for to change textLabel, backgroundColor, separator ecc I tried to set an identifier to each cel but didn't work...

like image 282
Fabio Cenni Avatar asked Dec 08 '22 02:12

Fabio Cenni


1 Answers

For static cells created in the storyboard, you can simply set the IBOutlet for the elements you want to edit by ctrl-dragging from the storyboard to the corresponding view controller, to end up with something like this:

class MyViewController: UIViewController {
  @IBOutlet weak var cell1: UITableViewCell!
  @IBOutlet weak var cell2: UITableViewCell!
}

Then you can access the built-in elements in the Basic view with cell1.textLabel etc.

Check out the documentation about setting IBOutlets.

To change the background color, you can do it in the storyboard UI directly or access the backgroundColor property. You might want to read the UITableViewCell Class Reference.

like image 94
p4sh4 Avatar answered Dec 28 '22 07:12

p4sh4