XCode6/Swift: unrecognized selector sent to instance

后端 未结 3 1022
北恋
北恋 2021-02-15 10:58

Thought I\'d try my hand at iOS development since the Swift/ios8 announcement and I\'m having trouble getting a basic tableView to build.

Currently getting the following

相关标签:
3条回答
  • 2021-02-15 11:41

    It appears that your table's data source is not set to your ViewController class:

     -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb20fcf0
    

    Double check to make sure you've set up your XIB file/Storyboard properly.

    0 讨论(0)
  • 2021-02-15 11:43

    As indicated in the first line of your dump, you're trying to send ...numberOfRows... to an object of class UIViewController but that method is only implemented in your subclass.

    In your nib file you need to change the class of your view controller from UIViewController (the default) to ViewController.

    Open your storyboard (or nib file) select the controller itself (it has an icon at the bottom (or top in Xcode 6) that will say "View Controller" when you mouse over it.

    enter image description here

    Then select the 3rd icon from the properties panel and up at the top where it says "Custom Class" enter "ViewController"

    enter image description here

    0 讨论(0)
  • 2021-02-15 11:47

    Change your code to:

    override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
    
        // Return the number of rows in the section.
        return 10
    }
    
    0 讨论(0)
提交回复
热议问题