UITableViewController accessing static cells programmatically issue

后端 未结 6 1450
孤独总比滥情好
孤独总比滥情好 2021-01-05 23:41

Say I have a table with 10 static cells in it, is there a way to select a certain cell programmatically?

I\'ve tried this

UITableViewCell *cell = [se         


        
6条回答
  •  滥情空心
    2021-01-06 00:02

    This is a Swift 2.3. Solution.

    The UITableViewController is created in IB.

    /*
        NOTE
        The custom static cells must be
        In the IB tableview if one is being used 
        They also must be updated to be MYCustomTableViewCell 
        instead of UITableViewCell
    */
    import UIKit
    
    class MYCustomTableVC: UITableViewController
    {
        override func viewDidLoad()
        {
            super.viewDidLoad()
            // NO Nib registration is needed
        }
    
        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
        {
            let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) as! MYCustomTableViewCell
            // MYCustomTableViewCell can be created programmatically 
            // without a Xib file 
            return cell
        }
    }
    

提交回复
热议问题