Passing values from one view controller to another in Swift

Richa Goyal

I am working on Swift, I've got an error in tableview's didSelectRowAtIndexPath method. I want to pass a value to another view controller i.e 'secondViewController'. Here EmployeesId is an Array. The relevant code is as follows:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var view: Dashboard = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard") as Dashboard

    self.navigationController?.pushViewController(view, animated: true)
    secondViewController.UserId = employeesId[indexPath.item]  //getting an error here.
}

But I am getting this Error: fatal error: unexpectedly found nil while unwrapping an Optional value.

Any help will be appreciated.

Ron Fessler

Here's a general solution with two assumptions. First, UserId is not a UILabel. Second, you meant to use view which was instantiated in the second line, instead of using secondViewController

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var view: Dashboard = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard") as Dashboard

    self.navigationController?.pushViewController(view, animated: true)
    view.UserId = employeesId[indexPath.row]
}

Here's what Dashboard looks like:

class Dashboard: UIViewController {
    var UserId: String!
    @IBOutlet var userIDLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        userIDLabel.text = UserId
    }

    ...
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing values from one view controller to another in Swift

From Dev

Passing a "User" object from one view controller to another

From Dev

Passing a "User" object from one view controller to another

From Dev

Passing posted values from one controller to another in symfony

From Dev

passing data from one tab controller to another in swift

From Dev

Transfer Image View from one View Controller to another in Swift

From Java

Avoiding Delay from One View Controller to Another in Xcode using Swift

From Dev

Modifing one variable from another view controller swift

From Java

How to Navigate from one View Controller to another using Swift

From Dev

How to move data from one view controller to another in Swift?

From Dev

Swift watch. Sending data from one view controller to another

From Dev

pass an image from one view controller to another (swift) with Firebase

From Dev

Routing from one view to another controller's action method and passing a parameter to that controller's constructor

From Dev

passing values from One controller to another Controller using Session or TempData not working?

From Dev

Passing multiple models from one view to a controller

From Dev

Passing the values of foreach from controller to view

From Dev

passing array values from controller to view in cakephp

From Dev

facing difficulty passing values from view to controller

From Dev

Passing variables from one controller to another with $rootscope

From Dev

Passing Model from One Controller to Another

From Dev

How do i access/pass variable from another view controller? It's not the next view controller, but the view controller after the next one in Swift

From Dev

Passing JSON data from HTTP request to another view controller in Swift 3

From Dev

Passing data from one Backbone view to another

From Dev

passing product info from one view to another

From Dev

Passing Context From One Django View To Another

From Dev

Load function from one view controller from another view controller

From Dev

Passing a form from one controller's view to a completely different controller

From Dev

Passing a form from one controller's view to a completely different controller

From Dev

Passing form values from one page to another

Related Related

  1. 1

    Passing values from one view controller to another in Swift

  2. 2

    Passing a "User" object from one view controller to another

  3. 3

    Passing a "User" object from one view controller to another

  4. 4

    Passing posted values from one controller to another in symfony

  5. 5

    passing data from one tab controller to another in swift

  6. 6

    Transfer Image View from one View Controller to another in Swift

  7. 7

    Avoiding Delay from One View Controller to Another in Xcode using Swift

  8. 8

    Modifing one variable from another view controller swift

  9. 9

    How to Navigate from one View Controller to another using Swift

  10. 10

    How to move data from one view controller to another in Swift?

  11. 11

    Swift watch. Sending data from one view controller to another

  12. 12

    pass an image from one view controller to another (swift) with Firebase

  13. 13

    Routing from one view to another controller's action method and passing a parameter to that controller's constructor

  14. 14

    passing values from One controller to another Controller using Session or TempData not working?

  15. 15

    Passing multiple models from one view to a controller

  16. 16

    Passing the values of foreach from controller to view

  17. 17

    passing array values from controller to view in cakephp

  18. 18

    facing difficulty passing values from view to controller

  19. 19

    Passing variables from one controller to another with $rootscope

  20. 20

    Passing Model from One Controller to Another

  21. 21

    How do i access/pass variable from another view controller? It's not the next view controller, but the view controller after the next one in Swift

  22. 22

    Passing JSON data from HTTP request to another view controller in Swift 3

  23. 23

    Passing data from one Backbone view to another

  24. 24

    passing product info from one view to another

  25. 25

    Passing Context From One Django View To Another

  26. 26

    Load function from one view controller from another view controller

  27. 27

    Passing a form from one controller's view to a completely different controller

  28. 28

    Passing a form from one controller's view to a completely different controller

  29. 29

    Passing form values from one page to another

HotTag

Archive