Lawrence413 Lawrence413 - 4 months ago 8
Swift Question

Access static cell when pressing button

My issue is pretty simple but I can't figure out how to do it. I have a static cell and a button inside it.

I have an

IBAction
hooked to the button.

How do I access the cell inside the
IBAction
?


I tried:

let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 2, inSection: 1) as myStaticCell
cell.height = 200


But for an unknown reason to me, it takes both lines as a single expression.

Answer

You are missing a closing parenthesis on the method call. Add a second ) before your as keyword. You will also need to use as!.

You need to change:

let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 2, inSection: 1) as myStaticCell

To this:

let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 2, inSection: 1)) as! myStaticCell