I am looking to load data from my Firebase Database into a tableview in my main view controller and then pass that data to be more descriptive to a second view controller as my detail view controller. I am getting stuck because when i do click on the cell it will not segue to my other view controller and I am not sure how to get the data to pass. I want just the name on the first view controller and then the other data to populate on the detail view controller.
My Main View Controller--
import UIKit
import Foundation
import Firebase
import FirebaseDatabase
class ViewController: UIViewController {
var table = [FacStaffInfo]()
var ref: DatabaseReference!
#IBOutlet weak var Tableview: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
ref = Database.database().reference().child("users")
ref.observe(DataEventType.value, with: {(snapshot) in
if snapshot.childrenCount > 0 {
self.table.removeAll()
for user in snapshot.children.allObjects as! [DataSnapshot] {
let object = user.value as? [String: AnyObject]
let title = object?["title"]
let name = object?["name"]
let email = object?["email"]
let phone = object?["phone"]
let office = object?["office"]
let bio = object?["bio"]
let user = FacStaffInfo(title: title as! String, name: name as! String, email: email as! String, phone: phone as! Int, office: office as! String, bio: bio as! String)
self.table.append(user)
self.Tableview.reloadData()
}
}
})
}
}
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return table.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "userCell") as! TableViewCell
let user: FacStaffInfo
user = table[indexPath.row]
cell.titleLabel?.text = user.title
cell.nameLabel?.text = user.name
cell.emailLabel?.text = user.email
cell.phoneLabel?.text = String(user.phone)
cell.officeLabel?.text = user.office
cell.bioLabel?.text = user.bio
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = Tableview.indexPathForSelectedRow {
let destinationController = segue.destination as! InfoViewController
destinationController.FacStaffData = [table[indexPath.row]]
}
}
}
}
My Detail View controller--
import UIKit
import Firebase
import FirebaseDatabase
class InfoViewController: UIViewController {
var FacStaffData = [FacStaffInfo]()
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var emailLabel: UILabel!
#IBOutlet weak var phoneLabel: UILabel!
#IBOutlet weak var officeLabel: UILabel!
#IBOutlet weak var bioLabel: UILabel!
//var title = ""
var name = ""
var email = ""
var phone = ""
var office = ""
var bio = ""
override func viewDidLoad() {
super.viewDidLoad()
titleLabel.text = title
nameLabel.text = name
emailLabel.text = email
phoneLabel.text = phone
officeLabel.text = office
bioLabel.text = bio
print(titleLabel)
}
}
My info class--
import Foundation
import Firebase
import FirebaseDatabase
class FacStaffInfo {
var title: String
var name: String
var email: String
var phone: Int
var office: String
var bio: String
init(title: String, name: String, email: String, phone: Int, office: String, bio: String) {
self.title = title;
self.name = name;
self.email = email;
self.phone = phone;
self.office = office;
self.bio = bio
}
}
and my tableview cell--
import UIKit
import Firebase
import FirebaseDatabase
class TableViewCell: UITableViewCell {
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var emailLabel: UILabel!
#IBOutlet weak var phoneLabel: UILabel!
#IBOutlet weak var officeLabel: UILabel!
#IBOutlet weak var bioLabel: 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
}
}
It looks like didSelectRowAt just implements didSelectRowAt again without calling anything.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: self)
}
}
try again with:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: self)
}
Updated for followup:
The InfoViewController is using the default values. When you prepare the segue, you put the information into FacStaffData. This should do the trick.
class InfoViewController: UIViewController {
var FacStaffData = [FacStaffInfo]()
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var emailLabel: UILabel!
#IBOutlet weak var phoneLabel: UILabel!
#IBOutlet weak var officeLabel: UILabel!
#IBOutlet weak var bioLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
titleLabel.text = FacStaffData.title
nameLabel.text = FacStaffData.name
emailLabel.text = FacStaffData.email
phoneLabel.text = FacStaffData.phone
officeLabel.text = FacStaffData.office
bioLabel.text = FacStaffData.bio
print(titleLabel)
}
}
Related
I have a UI as given below and when i click save button in UI i want to add three values on top of the view to a table view, in which has three different labels for representing them and a custom structure to define the model. But my problem is that i can only append one element but what i want is to keep previously added elements in that array and show them in a tableView.
Here is the UI image
Here is the code:
MainViewController.swift
class MainViewController: UIViewController {
#IBOutlet weak var minDbLabel: UILabel!
#IBOutlet weak var averageDbLabel: UILabel!
#IBOutlet weak var maximumDbLabel: UILabel!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "saveRecord" {
let recordVC = segue.destination as! RecordTableViewController
recordVC.record.minimumValue = (minDbLabel.text! as NSString).floatValue
recordVC.record.averageValue = (averageDbLabel.text! as NSString).floatValue
recordVC.record.maximumValue = (maximumDbLabel.text! as NSString).floatValue
recordVC.recordsArray.append(recordVC.record)
}
}
#IBAction func save(_ sender: UIButton){
self.performSegue(withIdentifier: "saveRecord", sender: nil)
}
}
RecordTableViewController.swift:
class RecordCell: UITableViewCell {
#IBOutlet weak var dateLabel: UILabel!
#IBOutlet weak var minimumValueLabel: UILabel!
#IBOutlet weak var averageValueLabel: UILabel!
#IBOutlet weak var maximumValueLabel: UILabel!
}
class RecordTableViewController: UITableViewController {
let cellIdentifier: String = "cellID"
var recordsArray = [Record]()
var record: Record = Record()
override var shouldAutorotate: Bool {
return false
}
override func viewDidLoad() {
super.viewDidLoad()
let swipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight(_:)))
swipe.direction = .right
self.view.addGestureRecognizer(swipe)
tableView.insertRows(at: [IndexPath(row: recordsArray.count - 1, section: 0)], with: .automatic)
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recordsArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! RecordCell
cell.minimumValueLabel.text = "\(recordsArray[indexPath.row].minimumValue)"
cell.averageValueLabel.text = "\(recordsArray[indexPath.row].averageValue)"
cell.maximumValueLabel.text = "\(recordsArray[indexPath.row].maximumValue)"
return cell
}
}
Record.swift
struct Record {
var minimumValue: Float = .nan
var averageValue: Float = .nan
var maximumValue: Float = .nan
}
Thanks in advance.
Note: I already have searched on Google to find an answer but to no avail.
you should append the data in recordsArray in MainViewController first before performing the segue. See the code below
class MainViewController: UIViewController {
#IBOutlet weak var minDbLabel: UILabel!
#IBOutlet weak var averageDbLabel: UILabel!
#IBOutlet weak var maximumDbLabel: UILabel!
var recordsArray = [Record]()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "saveRecord" {
let recordVC = segue.destination as! RecordTableViewController
var record = Record()
record.minimumValue = Float(minDbLabel.text!) ?? 0.0
record.averageValue = Float(averageDbLabel.text!) ?? 0.0
record.maximumValue = Float(maximumDbLabel.text!) ?? 0.0
self.recordsArray.append(record)
recordVC.recordsArray = self.recordsArray
}
}
#IBAction func save(_ sender: UIButton){
self.performSegue(withIdentifier: "saveRecord", sender: nil)
}
}
Just replace your MainViewController with the code above and it should work.
I Have to do an app for recipes and it shows me different recipes in my tableView, and i just want to implement my CustomCell (from a xib file) to my storyboard and I don't know how to connect it to show my data (I already checked my identifier) here's the code of my controller :
class SearchRecipe: UIViewController, ShowAlert {
var recipeData = RecipeDataModel()
var recipe = [String]()
#IBOutlet weak var tableViewSearch: UITableView!
override func viewDidLoad() {
self.tableViewSearch.rowHeight = 130
}
func updateRecipeData(json: JSON){
if let ingredients = json["hits"][0]["recipe"]["ingredientLines"].arrayObject{
recipeData.ingredientsOfRecipe = ingredients[0] as! String
recipeData.cookingTime = json["hits"][0]["recipe"]["totalTime"].stringValue
recipeData.recipe = json["hits"][0]["recipe"]["label"].stringValue
recipeData.recipeImage = json["hits"][0]["recipe"]["image"].stringValue
}
else {
print("Problem")
}
//self.tableViewSearch.reloadData()
}
}
extension SearchRecipe: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recipe.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customRecipeCell", for: indexPath) as! CustomRecipeCell
getRecipesDisplay(in: cell, from: recipeData , at: indexPath)
return cell
}
func getRecipesDisplay(in cell: CustomRecipeCell, from recipeModel: RecipeDataModel, at indexPath: IndexPath){
cell.recipeTitle.text = recipeData.recipe
cell.recipeInfos.text = recipeData.ingredientsOfRecipe
cell.timerLabel.text = recipeData.cookingTime
}
}
and this is the code my xib file :
class CustomRecipeCell: UITableViewCell {
#IBOutlet weak var recipeTitle: UILabel!
#IBOutlet weak var recipeInfos: UILabel!
#IBOutlet weak var cellImageBackground: UIImageView!
#IBOutlet weak var likeAndTimerView: UIView!
#IBOutlet weak var likeImage: UIImageView!
#IBOutlet weak var timerImage: UIImageView!
#IBOutlet weak var likeLabel: UILabel!
#IBOutlet weak var timerLabel: UILabel!
#IBOutlet weak var activityIndicator: UIActivityIndicatorView!
override func awakeFromNib() {
super.awakeFromNib()
activityIndicator.isHidden = true
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
In ViewDidLoad, you must register your cell this way:
override func viewDidLoad() {
tableViewSearch.register(UINib(nibName:" /* NAME OF YOUR XIB FILE */ ", bundle: nil), forCellReuseIdentifier: "customRecipeCell")
}
You also have to edit the size of your cell in the attribute inspector of your custom cell and of your table view
So, I have a UIViewController(PledgeViewController) with a TableView. When the user clicks on a UIButton(plusBtn) in the UITableViewCell(PledgeTableViewCell) of the TableView, I want to perform a write to my firebase database. But to get the exact path, I need a String(getID) from the PledgeViewController class which is received with a segue from the previous ViewController. With the MVC format that I'm using, how do I access values in the PledgeViewController to write to the database from the PledgeTableViewCell?
My PledgeViewController.swift:
import UIKit
import Foundation
import FirebaseDatabase
import Firebase
class PledgeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
var getID: String!
#IBOutlet weak var pledgeAmtLabel: UILabel!
#IBOutlet weak var RewardChooseTable: UITableView!
#IBAction func pledgeBtn(_ sender: Any) {
//get the text from the label and run all the checks to see if the tickets are available
}
let RewardRef = Database.database().reference().child("Rewards")
var rewards = [Rewards]()
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rewards.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TakePledgeCell", for: indexPath) as! PledgeTableViewCell
let reward = rewards[indexPath.row]
cell.reward = reward
return cell
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
RewardRef.child(getID).observe(.value, with: { (snapshot) in
self.rewards.removeAll()
for child in snapshot.children {
let childSnapshot = child as! DataSnapshot
let reward = Rewards(snapshot: childSnapshot)
self.rewards.insert(reward, at: 0)
}
self.RewardChooseTable.reloadData()
})
}
override func viewDidLoad() {
super.viewDidLoad()
print("The id received from the SingleViewControl is:" + getID)
}
}
My PledgeTableViewCell.swift:
import UIKit
import Firebase
import FirebaseDatabase
class PledgeTableViewCell: UITableViewCell {
#IBOutlet weak var rewardAmtLabel: UILabel!
#IBOutlet weak var ticketClasslabel: UILabel!
#IBOutlet weak var ticketDescLabel: UILabel!
#IBOutlet weak var ticketCountLabel: UILabel!
#IBOutlet weak var plusBtn: UIButton!
#IBOutlet weak var minusBtn: UIButton!
var ref: DatabaseReference!
var artcallid: Int!
#IBAction func minusBtn(_ sender: Any) {
}
var reward: Rewards! {
didSet {
rewardAmtLabel.text = "Rs. " + String(reward.rewardAmt)
ticketClasslabel.text = reward.reward_class_name
ticketDescLabel.text = reward.reward_desc
print(reward.reward_class_name + " is one of the rewards")
}
}
#IBAction func plusBtn(_ sender: AnyObject) {
}
}
Rewards.swift:
import Foundation
import Firebase
import FirebaseDatabase
class Rewards {
let ref: DatabaseReference!
// let countRef: DatabaseReference!
var rewardAmt: Int!
var rewardsLeft: Int!
var reward_class_name: String = ""
var reward_amt: String = ""
var reward_desc: String = ""
var rewardID: String = ""
var tickUpCount = 0
var tickDownCount = 0
init(text: String) {
ref = Database.database().reference().child("Fund").childByAutoId()
// countRef = Database.database().reference().child("Testing").childByAutoId()
}
init(snapshot: DataSnapshot)
{
ref = snapshot.ref
if let value = snapshot.value as? [String : Any] {
rewardAmt = value["reward_ticket_amount"] as! Int
reward_class_name = value["reward_ticket_amount_class_name"] as! String
reward_amt = value["reward_ticket_amount_txt"] as! String
reward_desc = value["reward_ticket_class_desc"] as! String
rewardsLeft = value["rewards_left"] as! Int
rewardID = snapshot.key
}
}
}
extension Rewards{
func countUp(){
tickUpCount += 1
ref.child("uppingTicket").setValue(tickUpCount)
}
}
You can try with closure
class PledgeTableViewCell: UITableViewCell {
//Define a closure
var closure:(() -> Void)? = nil
#IBAction func plusBtn(_ sender: AnyObject) {
// Do you stuff
closure?()
}
}
class PledgeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TakePledgeCell", for: indexPath) as! PledgeTableViewCell
let reward = rewards[indexPath.row]
cell.reward = reward
cell.closure = {
// You will get the callback in this block
// You can define the parameterized closure to return the value
}
return cell
}
You can try to add a new var
class PledgeTableViewCell: UITableViewCell {
var currentID = ""
}
and set it in cellForRowAt
cell.currentID = getID
I'm currently working on a Master-DetailView application and I'm stuck on how to make the data change....
I saw a great tutorial on how to do this :
Tutorial
But the guy is using a blank ViewController & I'm using a TableViewController With static Cells,So it doesn't work.
I want to put the data manually like
var Label1Data = ["You Tapped Cell 1,You Tapped Cell 2,You Tapped Cell 3"]
and it will show in the DetailView by the index path if i pressed the first cell the first data will show up in that Label...i know its not ideal to use static cells here but i do wanna use them design wise.
It will be great if any one could show me finally how can i put the data successfully like i said above and how the Tutorial does it.
MasterViewController Code:
import UIKit
import AVFoundation
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate{
#IBOutlet var tableViewController: UITableView!
var audioPlayer = AVAudioPlayer()
var sel_val : String?
// TableView Data :
struct User {
var name: String
var streetName: String
var image: UIImage?
}
var allUsers: [User]!
var filteredUsers: [User]!
func createUsers(names: [String], streets: [String], images: [UIImage?]) -> [User] {
var users = [User]()
guard names.count == streets.count && names.count == images.count else { return users }
for (index, name) in names.enumerated() {
let user = User(name: name, streetName: streets[index], image: images[index])
users.append(user)
}
return users
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return self.names.count
} else {
return self.filteredUsers.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell
let user:User!
if tableView == self.tableView {
user = allUsers[indexPath.row]
} else {
user = filteredUsers[indexPath.row]
}
cell.photo.image = user.image
cell.name.text = user.name
cell.streetName.text = user.streetName
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let object = self.storyboard?.instantiateViewController(withIdentifier: "BarProfileTableViewController") as! BarsProfile
let user:User!
if tableView == self.tableView {
user = allUsers[indexPath.row]
} else {
user = filteredUsers[indexPath.row]
}
print("username : \(user.name)")
print("streetName : \(user.streetName)")
MyIndex = indexPath.row
object.barImage = user.image!
object.barName = user.name
object.streetName = user.streetName
self.navigationController?.pushViewController(object, animated: true)
}
DetailView's Code:
import UIKit
import AVFoundation
import MapKit
class BarsProfile: UITableViewController,MKMapViewDelegate {
#IBOutlet var Distance: UILabel!
#IBOutlet var headerImage: UIImageView!
#IBOutlet var OnlineMenu: UIButton!
#IBOutlet var Address: UILabel!
#IBOutlet var ProfileMapView: MKMapView!
#IBOutlet var BarNameLBL: UILabel!
#IBOutlet var streetNameLBL: UILabel!
#IBOutlet var MusicLabel: UILabel!
#IBOutlet var KindOfBarCell: UITableViewCell!
var barName = String()
var barImage = UIImage()
var streetName = String()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
BarNameLBL.text = barName
streetNameLBL.text = streetName
navigationItem.title = barName
}
How it looks like : ( Red line is a label i would like to put data manually in)
you cant use a TableViewController for your purpose. Instead you can use a normal ViewController with labels and textfields.
In the above picture of yours, you can use a simple label of width = 1 and color = lightGrey so that you can get the same separator line as in the tableview.
First of all, I am a beginner! So it's a bit complicated, but basically I am trying to create a separate view controller that displays information held in a struct/string with objects. I am making a directory. I have two controllers, one for the tableView (called DirectoryTableViewController) and one for the detail view (called FacultyViewController) and then I have a swift file (called People) that has manages the String.
I am eventually going to add name, phone, email and an image to the String, but for now I am just doing the names.
My problem is that it is working and I need some pointers. Thanks!!
Here is my DirectoryTableView:
import UIKit
struct peoples {
var teacherString: String!
var image: UIImage!
}
class DirectoryTableViewController: UITableViewController {
var detailViewController: DetailViewController? = nil
var array : [People]!
override func viewDidLoad() {
super.viewDidLoad()
print(array)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("directoryCell", forIndexPath: indexPath)
let person = array[indexPath.row]
cell.textLabel!.text = person.teacherString
return cell
}
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
}
Here is my NewViewController:
import UIKit
class NewViewController: UIViewController {
#IBOutlet weak var nameTextField: UITextField!
#IBOutlet weak var phoneTextField: UITextField!
#IBOutlet weak var emailTextTield: UITextField!
var array : [People] = []
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func crateObjectButton(sender: AnyObject) {
let object = People(name: nameTextField.text! , phone: phoneTextField.text!, email: emailTextTield.text!)
array.append(object)
performSegueWithIdentifier("TeacherData", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "TeacherData" {
let dvc = segue.destinationViewController as? DirectoryTableViewController
dvc!.array = array
}
}
}
Here is People.swift (model):
import Foundation
class People {
var name : String
var phone: String
var email: String
init(name: String, phone: String, email: String) {
self.name = name
self.phone = phone
self.email = email
}
}
Thanks again!
As per your question , you have to make a model
import Foundation
class People {
var name : String
var phone: String
var email: String
init(name: String, phone: String, email: String) {
self.name = name
self.phone = phone
self.email = email
}
}
and make a view controller from where you gather all these details for eg: like this
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var nameTextField: UITextField!
#IBOutlet weak var phoneTextField: UITextField!
#IBOutlet weak var ageTextTield: UITextField!
var array : [People] = []
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func crateObjectButton(sender: AnyObject) {
let object = People(name: nameTextField.text! , phone: phoneTextField.text!, email: ageTextTield.text!)
array.append(object)
performSegueWithIdentifier("TeacherData", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "TeacherData" {
let dvc = segue.destinationViewController as? TableviewController
dvc!.array = array
}
}
}
and this segue take you to the tableviewcontroller where in viewdidLoad i am printing the array of teachers.
import UIKit
class TableviewController: UITableViewController {
var array : [People]!
override func viewDidLoad() {
super.viewDidLoad()
print(array)
}
}
and you go to the deatil view controller of a selected teacher by using this method:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
object = array![indexPath.row]
performSegueWithIdentifier("yourdetailviewcontrollersegue", sender: self)
}