user1092808
user1092808

Reputation: 393

Calling super for cellForRowAtIndexPath in Swift

I would greatly appreciate it someone could help me with the syntax for calling super to get the UITableViewCell from within func tableView (tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!). This is a static table.

override func tableView (tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
//  The Objective-C code is: UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
var cell = super.??
}

I have tried and tried, but cannot seem to get the correct syntax for doing this. Thanks in advance.

Upvotes: 9

Views: 4385

Answers (4)

Venc
Venc

Reputation: 115

In Swift 4 and ios 10+

  1. Create outlets.
  2. oneCellOutlets.IsHidden = true

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    
    if cell.isHidden == true
    {
        return 0
    }
    else{
        return super.tableView(tableView, heightForRowAt: indexPath)
    }
    }
    

Upvotes: 0

Josh Hinman
Josh Hinman

Reputation: 6805

var cell = super.tableView(tableView, cellForRowAt: indexPath)

Upvotes: 16

What it worked to me was.

let cell = someController.tableView.cellForRow(at: NSIndexPath(row: item, section: 0) as IndexPath) 

Upvotes: 1

kee23
kee23

Reputation: 148

Update for Swift 3:

var cell = super.tableView(tableView, cellForRowAt: indexPath)

Upvotes: 3

Related Questions