Created
June 7, 2014 01:37
-
-
Save Greyeye/296ed572df88026b2ad6 to your computer and use it in GitHub Desktop.
prepareforsegue usecase (subclass UITableViewController)
written in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JamesTableViewController.swift | |
// swiftTest | |
// | |
// Created by James Hong on 6/06/2014. | |
// Copyright (c) 2014 James Hong. All rights reserved. | |
// | |
import UIKit | |
class JamesTableViewController: UITableViewController, UITableViewDataSource{ | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { | |
return 1 | |
} | |
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int { | |
return 10 | |
} | |
//create one new cell on the tableView | |
//this gets called for each rows | |
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { | |
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell | |
cell.textLabel.text = "ROW #\(indexPath.row)" | |
return cell | |
} | |
//match obj DetailsViewController(this is a custom subClass of UIViewController) | |
//with segue destinationViewController | |
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) { | |
//if there are multipe segue, perform the task on only matching segue name "toItems" | |
//this value is set on IB | |
if (segue!.identifier == "toItems") { | |
let itemviewcontroller = segue!.destinationViewController as | |
//set variable inside the DetailsViewController.newText to "change me" | |
itemviewcontroller.newText = "change me" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment