Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var tableView: UITableView!
- var itemsArray: [ToDoItem] = []
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return itemsArray.count
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell!
- let tempItem = itemsArray[indexPath.row]
- cell.textLabel?.text = tempItem.itemName
- return cell!
- }
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- if segue.identifier == "detailsegue" {
- let destVC = segue.destinationViewController as! DetailViewController
- let selectedIndex = tableView.indexPathForSelectedRow
- destVC.myItem = itemsArray[selectedIndex!.row] as? ToDoItem
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- let item1 = ToDoItem(name: "Eat", desc: "Eat until i am full. I prefer local food though!", place: "Food Court")
- itemsArray.append(item1)
- let item2 = ToDoItem(name: "Drink", desc: "Drink until i am full. I prefer local drink though!", place: "Drink Court")
- itemsArray.append(item2)
- let item3 = ToDoItem(name: "Jump", desc: "Jump until i am tired. I prefer local jump though!", place: "Sport Center")
- itemsArray.append(item3)
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
- init(name: String, desc: String?, place:String?) {
- self.itemName = name
- self.itemDescription = desc
- self.itemPlace = place
- self.completed = false
- }
- import UIKit
- class DetailViewController: UIViewController {
- var myItem: ToDoItem?
- @IBOutlet weak var nameLabel: UILabel!
- @IBOutlet weak var placeLabel: UILabel!
- @IBOutlet weak var descLabel: UILabel!
- override func viewDidLoad() {
- super.viewDidLoad()
- nameLabel.text = myItem?.itemName
- placeLabel.text = myItem?.itemDescription
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement