0

so I have a UIScrollView with all of these buttons overlayed with images:

https://i.stack.imgur.com/NsOby.png

and I need it so that if you click on a teacher, like Mr Edmondson for maths, In another UIViewController, an email screen pops up and it needs to set the email recipient to edmondson@gmail.com.

Basically you click on whatever teacher, and it sets the email recipient to that teacher. My current code in the recipients & message body is:

let toRecipients = ["placeholder@gmail.com"]
mc.setMessageBody("blah blah blah blah")

How would I do this ?

Steve Left
  • 11
  • 2

3 Answers3

0

You may use segue in your storyboard. Then use the prepareSegue

Something like this in your TableViewController

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "detailSegue" {
    let vc = segue.destination as! ViewController
    vc.teacher = teachers[selectedItem]
   }
} 

You must manage the selected teacher with a var selectedItem: Int in

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectedItem = indexPath  
        print (selectedItem.row) 
    }

If it's not clear, feel free to give me more details about your code if you need more explanations.

Regards Seb

Sébastien REMY
  • 2,399
  • 21
  • 39
  • I have the scrollview with buttons in ScreenView3, and the email recipient on ScreenView5, so they are not directly together, will this effect the code? – Steve Left Jun 06 '17 at 08:46
0

Create a property in viewcontoller and set it in prepareForSegue method.

Pramod
  • 56
  • 6
0

Have a look at the following instance method:

prepareForSegue:sender:

Use this method to let your end view controller know which teacher that you have selected and in the next view controller where you need to automatically load the teacher's email address you can do the following:

Save all your teachers data (including the names, email address etc.) into a CoreData model then load the selected teachers email address when required.

It's kind of hard to explain in detail as I have no idea how your code is structured and whatnot.

Mr10k
  • 157
  • 1
  • 10