Monthly Archives: November 2016

Table View with Sections and Headings


import UIKit

class ViewController: UIViewController, UITableViewDataSource {
 let dailyTask = ["check all windows","check all doors","check temperature of freezer","check the mailbox at the end of the lane","Empty trash containers","if freezing, check water pines outside"]
 let weeklyTasks = ["check inside all unoccupied cabins","Run all faucets for 30 seconds","Arraunge for dumpster pickup"]
 let twoWeekTasks = ["run test on security alarm","check all motion detectors","Test smoke a alarm"]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 3 // how many section have
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 switch section {
 case 0:
 return dailyTask.count
 case 1:
 return weeklyTasks.count
 case 2:
 return twoWeekTasks.count
 default:
 return 0
 }
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 var currentTask: String
 switch indexPath.section {
 case 0:
 currentTask = dailyTask[indexPath.row]
 case 1:
 currentTask = weeklyTasks[indexPath.row]
 case 2:
 currentTask = twoWeekTasks[indexPath.row]
 default:
 currentTask = ""
 }
 cell.textLabel!.text = currentTask
 return cell
 }
 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
 switch section {
 case 0:
 return "Daily Tasks"
 case 1:
 return "Weekly Tasks"
 case 2:
 return "Every Two Weeks"
 default:
 return "This Should Not Be Here" }
 }

 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.
 }

}

Table View with Number List

// Created by Mohammad Azmal Hossain on 11/22/16.
// Copyright © 2016 Mohammad Azmal Hossain. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return 10
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 cell.textLabel!.text = "this is row \(indexPath.row)"
 return cell
 }
 
 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.
 }


}

Table View Part-2

// Created by MohammadAzmalHossain on 11/19/16.


import UIKit

class ViewController: UIViewController, UITableViewDataSource {
 let devCourse = [("ios app development with swift training","simon allardice"),("ios 8 SDK new features","Lee BrimeLow"),("Data visualization with D3.js","Ray Villaglobos"),("swift essential training","simon allardice"),("Up and Running with AngularJS","Dan Gookin"),("MySQL Essential Training","Scott Simpson"),("Building Adaptive andraid apps with franments","David Gassner")]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 1
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return devCourse.count
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 let (courseTitle, courseAuthor) = devCourse[indexPath.row]
 cell.textLabel?.text = courseTitle
 return cell
 
 
 }
 
 
 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.
 }


}

Table View

// Created by MohammadAzmalHossain on 11/19/16.
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
 func numberOfSections(in tableView: UITableView) -> Int {
 return 1
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return 5
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 cell.textLabel?.text = "Hello World"
 return cell
 }
 
 
 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.
 }
}