Table View Part-3

import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let dailyTask = [ "Check all windows", "check all doors", "check temperature of freezer","check the mailBox at at the end fo the lane","empty trash containers","if freezing, check water popes outside"]
 let weeklyTasks = ["check inside all unoccupied cabins", "run all faucets for 30 seconds","Walk the perimeter of property", "Arrange for dumpster pickup"]
 let twoWeekTasks = ["Run test on security alarm","check all motion detectors","Test smoke alarms"]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 3 // declared 3 array formar
 }
 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 "Dail 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.
 }

 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s