In my first view controller, I have the segmented control. I am trying to get the string value of the title of the selected part of the segmented control from my second view controller. Anyone have any idea on how to do this? Thanks in advance!
You don't have any code written, but I presume that this is a present and dismiss view controller scenario, not addchildviewcontroller
or addsubview
. In that case there are lots of ways to do it, here are two:
1) Make a global variable that detects the status of segmented control.
@IBOutlet weak var segContoll: UISegmentedControl!
func back() {
globalvar = segContoll.titleForSegment(at: segContoll.selectedSegmentIndex)
}
2) Make a protocol, here is what it should look like:
protocol NotifyDelegate {
func collectionViewSelectedIndex(indexPath : Int)
}
class CollectionViewForSessions: ... {
var delegate: NotifyDelegate?
func ... {
//The nextview delegate
sessionCollection.delegate = self
}
func ... {
//Instead of inputing a number, customize it to input a string segContoll.titleForSegment(at: segContoll.selectedSegmentIndex)
delegate?.collectionViewSelectedIndex(indexPath: indexPath.row)
}
}
class MessagesWithPerson: NotifyDelegate {
func collectionViewSelectedIndex(indexPath: Int) {
}
}