我的问题很简单,但是我不知道该怎么做。我有一个静态单元格和一个按钮。

我有一个IBAction挂在按钮上。

如何访问IBAction中的单元格?

我试过了:

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


但是出于我未知的原因,它把这两行都作为一个表达式。

最佳答案

您在方法调用上缺少右括号。在)关键字之前添加第二个as。您还需要使用as!

您需要更改:

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


对此:

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

关于swift - 按下按钮时访问静态单元格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38440612/

10-14 16:54
查看更多