Skip to content

Instantly share code, notes, and snippets.

@Greyeye
Created June 7, 2014 01:37
Show Gist options
  • Save Greyeye/296ed572df88026b2ad6 to your computer and use it in GitHub Desktop.
Save Greyeye/296ed572df88026b2ad6 to your computer and use it in GitHub Desktop.
prepareforsegue usecase (subclass UITableViewController) written in Swift
//
// 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