How to reference tableView from a view controller during a segue

前端 未结 4 614
旧时难觅i
旧时难觅i 2020-12-15 11:35

I\'m new to iOS development, so go easy on me please :)

Using Xcode 4.2 for iOS 5, I\'ve built a view controller in IB, with a tableview inside it linked to a detail

4条回答
  •  心在旅途
    2020-12-15 12:12

    SWIFT 2 UPDATE

    I "hooked up" the tableView as an outlet from the storyboard in the ViewController.

    like this: @IBOutlet weak var tableView: UITableView!

    Just drag your tableView into the ViewController and make it an outlet. Then you can reference its properties such as self.tableView.reloadData().

    This property as well as others that referenced the tableView were giving me errors until I added the tableView as a referencing outlet.

    Add this to your class: class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate

    The indexPath.row should now work, as well as the segues. You can also use instantiateViewControllerWithIdentifier like this:

      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
            let myOtherView = self.storyboard!.instantiateViewControllerWithIdentifier("otherViewController") as! otherViewViewController
    
    
                myOtherView.url = NSURL(string:"\(array[indexPath.row])")
    
                self.presentViewController(myOtherView, animated: true, completion: nil)
    
    
        }
    

    Hope that helps.

提交回复
热议问题