I have a tableView with static cells.
What I wan't, is that when the user selects a certain cell, the text from this cell, is passed to the previous viewController. I have never worked with static cells before and I can only seem to find tutorials and other questions regarding activating the cells, so they leed to another viewController.
So how do I pass data (what's written in the cell), when the cell is selected?
Is it a code in didSelectRowAtIndexPath?
Do I use segues? Then there will have to be hundreds of segues, if I have hundreds of cell, that the user can choose, right?
Thanks!
First you are assigning Array of String to DiaryQuestionLabel.text which accepts string only in destinationViewController. Just change the type of chosenQuestion to String in destinationViewController as below.
#IBOutlet weak var DiaryQuestionLabel: UILabel!
var chosenQuestion: String = ""
override func viewDidLoad() {
super.viewDidLoad()
DiaryQuestionLabel.text = chosenQuestion
}
In your tableViewController You need to pass the value of selected index from your datasource array which you have used to set the data in your tableviewcell.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is UpdatingIdentifiers {
let vc = segue.destination as? UpdatingIdentifiers
let selectedRowIndex = self.tableView.indexPathForSelectedRow()
// Get tableviewcell object from indexpath and assign it's value to chosenQuestion of another controller.
let cell = yourtableview.cellForRow(at: selectedRowIndex)
let label = cell.viewWithTag(420) as! UILabel
vc?.chosenQuestion = label.text
}
}
You are attempting to assign the wrong type to your variables. That is the cause of your errors.
For example,
You have defined chosenQuestion as an array of String values, i.e. [String], but you are attempting to assign an IndexPath at the following statement, vc?.chosenQuestion = selectedRowIndex.
To fix your problem,
You need to extract the specific string from your data source by utilising the IndexPath that you have stored into the selectedRowIndex variable.
For example,
If your data source array is called, myArray, you can do the following:
var selectedRowIndex = self.tableView.indexPathForSelectedRow
vc?.chosenQuestion = myArray[selectedRowIndex]
and then change your variable,
var chosenQuestion = ""
Finally, inside viewDidLoad():
DiaryQuestionLabel.text = chosenQuestion
Text label is of type String. You are assigning an array of string to it.
Also the same mistake you are doing with assigning indexPath to an array of Strings.
You are messing around with types.
Change to this:
vc?.chosenQuestion = tableView.cellForRow(at: selectedRowIndex).textLabel?.text
Change your variable to
var chosenQuestion = ""
And in viewDidLoad()
DiaryQuestionLabel.text = chosenQuestion
How about a simple way. This is similar to Ali_Habeeb's answer with more details.
In your didSelectRowAt:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let question = yourDataArray[indexPath.row]
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let newVC = storyboard.instantiateViewController(withIdentifier: "newVCIdentifier") as! NewViewController
newVC.choosenQuestion = question
self.show(newVC, sender: self)
}
In your newVC:
class NewViewController: UIViewController {
#IBOutlet weak var DiaryQuestionLabel: UILabel!
var choosenQuestion = ""
override func viewDidLoad() {
super.viewDidLoad()
DiaryQuestionLabel.text = choosenQuestion
}
}
This is a very simple format, and should not produce any error and if does, then check your dataArray.
Related
In Swift 3, I'd like to pass the string contained in a cell of a UITableView into the subsequent View Controller.
As a note, I read several answers to this that seem to be specific to earlier versions of Swift, so I wanted to reopen. As an example, the last solution here looked straightforward, but I can't get it to work.
In TableViewController, I create a string of an audio file's name and date posted with this JSON extraction:
if let shows_list = json as? NSArray
{
for i in 0 ..< data_list.count
{
if let shows_obj = shows_list[i] as? NSDictionary
{
let episode_name = shows_obj["episode"] as? String
let episode_date = shows_obj["date"] as? String
TableData.append(episode_date! + " | " + episode_name!)
let testString = TableData.append(episode_date! + " | " + episode_name!)
// the part above runs and will add the string into each cell. now here, I want to pass the value of that string into a UILabel called episodeTitle in the target view controller
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let indexPath = self.tableView.indexPathForSelectedRow {
let destinationVC = segue.cellPasser
EpisodeViewController.text = testString //this is the string in second view controller
}
}
}
}
}
This is throwing two errors:
Value of type 'UIStoryboardSegue' has no member 'cellPasser'
In the Storyboard, I have added an identifier to the Show segue called 'cellPasser.' My belief is I should be able to call that here but it's being flagged.
EpisodeViewController.episodeTitle = testString
I have an outlet in EpisodeViewController that is called episodeTitle, so I am wondering if there is a preferred way other than this to pass strings into an element like that.
I'm new to Swift -- hoping someone sees a better way to do this.
Edit: In case useful, here's the View Controller linked from the segue.
class EpisodeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBOutlet var episodeTitle: UILabel!
Here are steps to pass value from TableViewController to next ViewController :
in TableViewController You should declare a didSelectRowAt method.
Declare a method prepare for segue
Do not forget to declare a variable in second view Controller.
1.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "Identifier", sender: indexPath)
}
2.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Identifier" {
let vc = segue.destination as! NameOfYourViewController
vc.variableInSecondVc = variableInTableView
}
}
3.
var variableInSecondVc = ""
I'm currently learning Swift and trying to perform a segue when the user taps on one of the tableview cells that the app presents. At the moment, whenever the user performs this action, the next view controller is loaded successfully, but it seems that, for some reason, I cannot access any of its UI elements, as each time that I try to do it, I end up getting this error:
fatal error: unexpectedly found nil while unwrapping an Optional value
The error points to the line in which I try to modify the text of one of the labels that are displayed on the next view controller
This is the didSelectRowAt function:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
self.performSegue(withIdentifier: "segue1", sender: self)
}
and this is the prepareForSegue function:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segue1" {
let destinationVC = segue.destination as! UserViewController
let selectedRow = tableView.indexPathForSelectedRow!
let selectedCell = tableView.cellForRow(at: selectedRow) as! CustomCell
destinationVC.usernameLabel.text = selectedCell.userName.text //this is where the error is pointing to
destinationVC.bioLabel.text = selectedCell.bio.text
destinationVC.userImage.image = selectedCell.photo.image
}
}
I have no idea about what is causing this problem. My goal is to pass the data from the tapped cell to the next view controller, but this obviously is preventing me from doing so. Does anyone know how I can fix this? Thanks in advance.
Note: I assumed that userName and bio were both UITextFields
Why don't you try something like this?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segue1" {
let destination = segue.destination as! UserViewController
// Use of optional binding to make sure an indexPath exists
if let indexPath = tableView.indexPathForSelectedRow {
let cell = tableView.cellForRow(at: IndexPath(row: indexPath.row, section: indexPath.section)) as! CustomCell
// Notice how we are not directly updating the label as before.
destination.usernameText = cell.userName?.text
destination.bioText = cell.bio?.text
}
}
}
Now in UserViewController:
#IBOutlet weak var usernameLabel: UILabel!
#IBOutlet weak var bioLabel: UILabel!
// What we will be passing the text to instead.
var usernameText: String?
var bioText: String?
override func viewDidLoad() {
super.viewDidLoad()
// update the labels with the text from the proper cell.
usernameLabel?.text = usernameText
bioLabel?.text = bioText
}
You can just do the same for your image, just different types. This has to do with the outlets not being allocated when used in prepare(for segue:).
i had great issue with the prepare for segue method when trying the same thing with a UICollectionView. The 2 are very similar so you should be able to change collectionview to tableview easily.
this is what i did... using variable selectedPack
in the view controller you want to segue to you need to set the variable
// passed packName from PackViewController
var selectedPack: String!
then in the viewcontroller you are selecting the cell
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// handle the segue to JourneyViewController with variable "selectedPack"
// not sure why you need to set the storyboard but it works
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
//create instance of the viewcontroller
let transportJourneyViewController = storyBoard.instantiateViewController(withIdentifier: "JourneyViewController") as! JourneyViewController
//value to pass - has been defined in journey
transportJourneyViewController.selectedPack = INSERT_YOUR_VALUE_TO_PASS
//present the vc
self.present(transportJourneyViewController, animated:true, completion:nil)
}
JourneyViewController is the storyboardID and ClassName of the viewcontroller you want to go to.set in the interface builder.
You'll also need to have the tableviewdatasource and tableviewdelegate defined at the top level of your view controllers and in the storyboard itself.
class JourneyViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
I'm still new to Swift, so please bear with me.
Currently I have loaded data from a JSON file and that is then displayed onto the individual cells.
I have a custom cell class which has the necessary label outlets (name and number).
What I want to do, is to retrieve data from a specified labels text when on a given row then pass it onto another ViewController.
e.g. Row 3 has two labels, "Data" and "2004". I have selected row 3 and would like to get this cells "2004" value and assign it to a variable that can be then passed to a different ViewController. ("2004" would be considered the number label outlet in my custom cell class i.e. cell.number)
Here is some code that may be of help:
Table View Controller
import UIKit
class TableViewController: UITableViewController, UINavigationControllerDelegate {
#IBOutlet var segmentedSortOption: UISegmentedControl!
var array : NSArray = DataClass.dataStruct.jsonResult["data"] as NSArray
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var myCell:cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as cell
var upperCasedNames = array[indexPath.row]["name"] as? String
if segmentedSortOption.selectedSegmentIndex == 0 {
myCell.No.text = array[indexPath.row]["no"] as? String
} else if segmentedSortOption.selectedSegmentIndex == 1 {
if let unsortedEvents = DataClass.dataStruct.jsonResult["data"] as NSArray {
let descriptor = NSSortDescriptor(key: "name", ascending: true, selector: "caseInsensitiveCompare:")
let aToZ = unsortedEvents.sortedArrayUsingDescriptors([descriptor])
myCell.No.text = aToZ[indexPath.row]["no"] as? String
}
}
return myCell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "selectedItem" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let destinationController = segue.destinationViewController as ViewController
destinationController.eventData = indexPath.row as Int
}
}
Custom Cell Class
import UIKit
class cell: UITableViewCell {
#IBOutlet var name: UILabel!
#IBOutlet var number: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
If you have any more questions, please do ask.
If you have a better alternative, please do suggest that as well.
Thanks!
EDIT: Forgot to mention a key issue. There is a segmented control that reorganises the data from the given order in the JSON file to an alphabetical order. The cells indexPath.row becomes useless in the instance of the A-Z view as the order is completely different.
In your prepareForSegue you need to get the cell you is selected with cellForRowAtIndexPath(is not the same tableView(tableView: UITableView, cellForRowAtIndexPath ) and the pass it to the destinationController, see the following example:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "selectedItem" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
// get the cell associated with the indexPath selected.
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as cell!
// get the label text to pass to destinationController
var text1 = cell.name.text
var text2 = cell.number.text
let destinationController = segue.destinationViewController as ViewController
destinationController.eventData = indexPath.row as Int
}
}
}
I hope this help you.
OK, I too am new to Swift, so bear with me. I see a few ways to do this.
1) You are throwing data into this tableview from a JSON file, right? So, depending on the structure of your project, maybe you can just get the index (row) clicked and use it to get the associated data from the JSON.
let indexPath = tableView.indexPathForSelectedRow();
Then pass that integer indexPath to whatever JSON parsing library you are using to get the associated data.
2) I'm not sure how the custom nature of your implementation changes things, but possibly this more generic question has your answer.
3) More of a hack-y solution, but maybe when you populate this UITableView you could set the tag of each cell to be its index, then you could just get it by tag and retrieve its label value that way (like in this SO answer)?
I am trying to update the UILabel on a previous Table View using an Unwinding Segue. I have everything working except I am bringing back blank text each time I select something on my modal. I am essentially bringing back the "" of the variable I am creating (myName).
However, I thought since I am updating the variable in my didSelectRowAtIndex that I would be bring that back. I did check to see if I am getting a value when selecting on the Modal and I am. So I think this is something as simple as updating the variable myName.
NewTableViewController (Modal):
var myName = ""
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let row = Int(indexPath.row)
var selectedObject = objects[row] as! PFObject
var selectedName = selectedObject["myName"] as! String
myName = selectedName as String
println(myName)
}
TableViewController (Source View Controller):
#IBAction func unwindName(segue: UIStoryboardSegue) {
println("unwind working")
if let svc = segue.sourceViewController as? NewTableViewController {
self.myNameLabel.text = svc.myName
println(myNameLabel)
}
}
When you invoke a segue (unwind or any other kind) from a cell, the segue will be executed before didSelectRowAtIndexPath is called, so you shouldn't set your variable value there (in fact you don't need to implement that method at all). You should implement prepareForSegue in the source view controller, and set the value of your variable there.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cell = sender as! UITableViewCell
let indexPath = self.tableView.indexPathForCell(cell)
var selectedObject = objects[indexPath.row] as! PFObject
var selectedName = selectedObject["myName"] as! String
myName = selectedName as String
}
I have a UITableView that populates Cells with data based on a JSON call. like so:
var items = ["Loading..."]
var indexValue = 0
// Here is SwiftyJSON code //
for (index, item) in enumerate(json) {
var indvItem = json[index]["Brand"]["Name"].stringValue
self.items.insert(indvItem, atIndex: indexValue)
indexValue++
}
self.tableView.reloadData()
How do I get the label of the cell when it is selected and then also pass that to another ViewController?
I have managed to get:
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow();
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
println(currentCell.textLabel.text)
}
I just cant figure out how to pass that as a variable to the next UIViewController.
Thanks
Passing data between two view controllers depends on how view controllers are linked to each other. If they are linked with segue you will need to use performSegueWithIdentifier method and override prepareForSegue method
var valueToPass:String!
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow();
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
valueToPass = currentCell.textLabel.text
performSegueWithIdentifier("yourSegueIdentifer", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "yourSegueIdentifer") {
// initialize new view controller and cast it as your view controller
var viewController = segue.destinationViewController as AnotherViewController
// your new view controller should have property that will store passed value
viewController.passedValue = valueToPass
}
}
If your view controller are not linked with segue then you can pass values directly from your tableView function
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow();
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
let storyboard = UIStoryboard(name: "YourStoryBoardFileName", bundle: nil)
var viewController = storyboard.instantiateViewControllerWithIdentifier("viewControllerIdentifer") as AnotherViewController
viewController.passedValue = currentCell.textLabel.text
self.presentViewController(viewContoller, animated: true , completion: nil)
}
You asked:
How do I get the label of the cell when it is selected and then also pass that to another ViewController?
I might suggest rephrasing the question as follows: "How do I retrieve the data associated with the selected cell and pass it along to another view controller?"
That might sound like the same thing, but there's an important conceptual distinction here. You really don't want to retrieve the value from the cell label. Our apps employ a MVC paradigm, so when you want to pass data information from one scene to another, you want to go back to the model (the items array), not the view (the text property of the UILabel).
This is a trivial example, so this distinction is a bit academic, but as apps get more complicated, this pattern of going back to the model becomes increasingly important. The string representation from the cell is generally is a poor substitute for the actual model objects. And, as you'll see below, it's just as easy (if not easier) to retrieve the data from the model, so you should just do that.
As an aside, you don't really need a didSelectRowAtIndexPath method at all in this case. All you need is a segue from the table view cell to the destination scene, give that segue a unique identifier (Details in my example), and then implement prepare(for:sender:):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? DetailsViewController {
let selectedRow = tableView.indexPathForSelectedRow!.row
destination.selectedValue = items[selectedRow]
}
}
Alternatively, if your segue is between the cell and destination scene, you can also use the sender of the prepare(for:sender:):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? DetailsViewController {
let cell = sender as! UITableViewCell
let selectedRow = tableView.indexPath(for: cell)!.row
destination.selectedValue = items[selectedRow]
}
}
But the idea is the same. Identify what row was selected, and retrieve the information from the model, the items array.
The above is Swift 3. For Swift 2.3, please see the previous version of this answer.
Okay..Its been 2 days I was searching for the answer that how could I be able to save the selected UITableViewCell label text data and display that data to an another label on an another View Controller which will come out after tapping on a cell. At last I have completed with the task and its successful. Here is the complete code with steps using Swift.I am using Xcode 6.4.
Step 1.
I have Two class assigned to the storyboard view controllers named "iOSTableViewControllerClass.swift" which is a Table View Controller and "iOSTutorialsViewControllerClass.swift" which is a normal View Controller.
Step 2.
Now make segue from iOSTableViewControllerClass to iOSTutorialsViewControllerClass by Control-dragging on the storyboard area and choose "show" from drop down menu. Click on this highlighted button according to the below image and perform the segue.
Step 3.
Now select the segue by clicking on the storyboard and give it an identifier on the Attributes Inspector. In this case I named it as "iOSTutorials"
Step 4.
Now on this step put a label on your cell as well as on the other view controller and make outlets of them on their corresponding classes.
In my case those are "#IBOutlet weak var iOSCellLbl: UILabel!" and " #IBOutlet weak var iOSTutsClassLbl: UILabel!".
Step 5.
Make a string type variable on the first Table View Controller Class. I did this as "var sendSelectedData = NSString()" also Make a string type variable on the second class. I did this as "var SecondArray:String!".
Step 6.
Now we are ready to go.
Here is the complete Code for first Class --
// iOSTableViewControllerClass.swift
import UIKit
class iOSTableViewControllerClass: UITableViewController, UITableViewDataSource,UITableViewDelegate {
// Creating A variable to save the text from the selected label and send it to the next view controller
var sendSelectedData = NSString()
//This is the outlet of the label but in my case I am using a fully customized cell so it is actually declared on a different class
#IBOutlet weak var iOSCellLbl: UILabel!
//Array for data to display on the Table View
var iOSTableData = ["Label", "Button", "Text Field", "Slider", "Switch"];
override func viewDidLoad() {
super.viewDidLoad()
//Setting the delegate and datasource of the table view
tableView.delegate = self
tableView.dataSource = self
//Registering the class here
tableView.registerClass(CustomTableViewCellClassiOS.self, forCellReuseIdentifier: "CellIDiOS")
//If your using a custom designed Cell then use this commented line to register the nib.
//tableView.registerNib(UINib(nibName: "CellForiOS", bundle: nil), forCellReuseIdentifier: "CellIDiOS")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return iOSTableData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let CellIDentifier = "CellIDiOS"
//In this case I have custom designed cells so here "CustomTableViewCellClassiOS" is the class name of the cell
var cell:CustomTableViewCellClassiOS! = tableView.dequeueReusableCellWithIdentifier(CellIDentifier, forIndexPath: indexPath) as? CustomTableViewCellClassiOS
if cell == nil{
tableView.registerNib(UINib(nibName: "CellForiOS", bundle: nil), forCellReuseIdentifier: CellIDentifier)
cell = tableView.dequeueReusableCellWithIdentifier(CellIDentifier) as? CustomTableViewCellClassiOS
}
//Here we are displaying the data to the cell label
cell.iOSCellLbl?.text = iOSTableData[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
// Get Cell Label text here and storing it to the variable
let indexPathVal: NSIndexPath = tableView.indexPathForSelectedRow()!
println("\(indexPathVal)")
let currentCell = tableView.cellForRowAtIndexPath(indexPathVal) as! CustomTableViewCellClassiOS!;
println("\(currentCell)")
println("\(currentCell.iOSCellLbl?.text!)")
//Storing the data to a string from the selected cell
sendSelectedData = currentCell.iOSCellLbl.text!
println(sendSelectedData)
//Now here I am performing the segue action after cell selection to the other view controller by using the segue Identifier Name
self.performSegueWithIdentifier("iOSTutorials", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//Here i am checking the Segue and Saving the data to an array on the next view Controller also sending it to the next view COntroller
if segue.identifier == "iOSTutorials"{
//Creating an object of the second View controller
let controller = segue.destinationViewController as! iOSTutorialsViewControllerClass
//Sending the data here
controller.SecondArray = sendSelectedData as! String
}
Here is the complete code for the second Class..--
// iOSTutorialsViewControllerClass.swift
import UIKit
class iOSTutorialsViewControllerClass: UIViewController {
//Creating the Outlet for the Second Label on the Second View Controller Class
#IBOutlet weak var iOSTutsClassLbl: UILabel!
//Creating an array which will get the value from the first Table View Controller Class
var SecondArray:String!
override func viewDidLoad() {
super.viewDidLoad()
//Simply giving the value of the array to the newly created label's text on the second view controller
iOSTutsClassLbl.text = SecondArray
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I do it like this.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedName = nameArray[indexPath.row]
let newView: nextViewName = self.storyboard?.instantiateViewController(withIdentifier: "nextViewName") as! nextViewName
newView.label.text = selectedValue
self.present(newView, animated: true, completion: nil)
}