1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| // ViewController.swift
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let devCourses = [ ("iOS App Dev with Swift Essential Training","Simon Allardice"), ("iOS 8 SDK New Features","Lee Brimelow"), ("Data Visualization with D3.js","Ray Villalobos"), ("Swift Essential Training","Simon Allardice"), ("Up and Running with AngularJS","Ray Villalobos"), ("MySQL Essential Training","Bill Weinman"), ("Building Adaptive Android Apps with Fragments","David Gassner"), ("Advanced Unity 3D Game Programming","Michael House"), ("Up and Running with Ubuntu Desktop Linux","Scott Simpson"), ("Up and Running with C","Dan Gookin") ] let webCourses = [ ("HTML Essential Training","James Williamson"), ("Building a Responsive Single-Page Design","Ray Villalobos"), ("Muse Essential Training","Justin Seeley"), ("WordPress Essential Training","Morten Rand-Hendriksen"), ("Installing and Running Joomla! 3: Local and Web-Hosted Sites","Jen Kramer"), ("Managing Records in SharePoint","Toni Saddler-French"), ("Design the Web: SVG Rollovers with CSS","Chris Converse"), ("Up and Running with Ember.js","Kai Gittens"), ("HTML5 Game Development with Phaser","Joseph Labrecque"), ("Responsive Media","Christopher Schmitt") ] func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 2 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return devCourses.count } else { return webCourses.count } } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) if indexPath.section == 0 { let (courseTitle,courseAuthor) = devCourses[indexPath.row] cell.textLabel?.text = courseTitle cell.detailTextLabel?.text = courseAuthor } else { let (courseTitle,courseAuthor) = webCourses[indexPath.row] cell.textLabel?.text = courseTitle cell.detailTextLabel?.text = courseAuthor } let myImage = UIImage(named: "star") cell.imageView?.image = myImage return cell } func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { if section == 0 { return "Developer Courses" } else { return "Web Courses" } } override func viewDidLoad() { super.viewDidLoad() // 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. } }
|