pEpForiOS/UI/Filter/FilterTableViewController.swift
changeset 1832 8f9685564441
child 1836 908ef2563c5e
equal deleted inserted replaced
1831:eeada9973971 1832:8f9685564441
       
     1 //
       
     2 //  FilterTableViewController.swift
       
     3 //  pEpForiOS
       
     4 //
       
     5 //  Created by Xavier Algarra on 13/03/2017.
       
     6 //  Copyright © 2017 p≡p Security S.A. All rights reserved.
       
     7 //
       
     8 
       
     9 import UIKit
       
    10 
       
    11 class FilterTableViewController: UITableViewController {
       
    12 
       
    13     open var inFolder: Bool = false
       
    14 
       
    15     var sections = [FilterViewModel]()
       
    16 
       
    17     override func viewDidLoad() {
       
    18         super.viewDidLoad()
       
    19 
       
    20         // Uncomment the following line to preserve selection between presentations
       
    21         // self.clearsSelectionOnViewWillAppear = false
       
    22 
       
    23         // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
       
    24         // self.navigationItem.rightBarButtonItem = self.editButtonItem()
       
    25     }
       
    26 
       
    27     override func viewWillAppear(_ animated: Bool) {
       
    28         initViewModel()
       
    29 
       
    30     }
       
    31 
       
    32     func initViewModel() {
       
    33         if !inFolder {
       
    34             sections.append(FilterViewModel(type: .accouts))
       
    35         }
       
    36         sections.append(FilterViewModel(type: .include))
       
    37         sections.append(FilterViewModel(type: .to))
       
    38         sections.append(FilterViewModel(type: .other))
       
    39     }
       
    40 
       
    41     override func didReceiveMemoryWarning() {
       
    42         super.didReceiveMemoryWarning()
       
    43         // Dispose of any resources that can be recreated.
       
    44     }
       
    45 
       
    46     // MARK: - Table view data source
       
    47 
       
    48     override func numberOfSections(in tableView: UITableView) -> Int {
       
    49         // #warning Incomplete implementation, return the number of sections
       
    50         return sections.count
       
    51     }
       
    52 
       
    53     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       
    54         // #warning Incomplete implementation, return the number of rows
       
    55         return sections[section].count
       
    56     }
       
    57 
       
    58     override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
       
    59         return sections[section].title
       
    60     }
       
    61     override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
       
    62         return 40.0
       
    63     }
       
    64 
       
    65     override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
       
    66 
       
    67         let header = view as! UITableViewHeaderFooterView
       
    68         header.textLabel?.font = UIFont(name: "Futura", size: 11)
       
    69         header.textLabel?.textColor = UIColor.lightGray
       
    70 
       
    71     }
       
    72 
       
    73     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       
    74         let cell = tableView.dequeueReusableCell(withIdentifier: "filterCell", for: indexPath)
       
    75         //cell.imageView?.image = FlagImages.create(imageSize: cell.imageView?.image).flaggedImage
       
    76         let cellvm = sections[indexPath.section][indexPath.row]
       
    77         cell.textLabel?.text = cellvm.title
       
    78         cell.imageView?.image = cellvm.icon
       
    79         return cell
       
    80     }
       
    81 
       
    82     /*
       
    83     // Override to support conditional editing of the table view.
       
    84     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
       
    85         // Return false if you do not want the specified item to be editable.
       
    86         return true
       
    87     }
       
    88     */
       
    89 
       
    90     /*
       
    91     // Override to support editing the table view.
       
    92     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
       
    93         if editingStyle == .delete {
       
    94             // Delete the row from the data source
       
    95             tableView.deleteRows(at: [indexPath], with: .fade)
       
    96         } else if editingStyle == .insert {
       
    97             // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
    98         }    
       
    99     }
       
   100     */
       
   101 
       
   102     /*
       
   103     // Override to support rearranging the table view.
       
   104     override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
       
   105 
       
   106     }
       
   107     */
       
   108 
       
   109     /*
       
   110     // Override to support conditional rearranging of the table view.
       
   111     override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
       
   112         // Return false if you do not want the item to be re-orderable.
       
   113         return true
       
   114     }
       
   115     */
       
   116 
       
   117     /*
       
   118     // MARK: - Navigation
       
   119 
       
   120     // In a storyboard-based application, you will often want to do a little preparation before navigation
       
   121     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
       
   122         // Get the new view controller using segue.destinationViewController.
       
   123         // Pass the selected object to the new view controller.
       
   124     }
       
   125     */
       
   126 
       
   127 }