2017年3月20日 星期一

swift 3 dialog

let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)) 
self.present(alert, animated: true, completion: nil)

http://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift

2017年3月1日 星期三

PageViewControl第一次使用

1. 拉一個 PageViewController
2. 開多個 ViewControl
3. 概念大概是一個底頁(MorePageViewController) 上面有一層頁面作切換

//
//  MorePageViewController.swift
//  tempertureBLE
//
//  Created by Quanta.ux  on 2017/3/1.
//  Copyright © 2017 QuantaPDC. All rights reserved.
//

import UIKit

class MorePageViewController: UIPageViewController,UIPageViewControllerDataSource, UIPageViewControllerDelegate {

    lazy var VCArr:[UIViewController] = {
        return[self.VCInstance(name:"FirstVC"),
               self.VCInstance(name:"SecondVC"),
               self.VCInstance(name:"ThirdVC")]
    }()
    
    private func VCInstance(name:String)->UIViewController{
        return UIStoryboard(name:"Main" , bundle:nil).instantiateViewController(withIdentifier: name)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.dataSource = self
        self.delegate = self
        if let firstVC = VCArr.first{
            setViewControllers([firstVC], direction: .forward, animated: true, completion: nil)
        }
        // Do any additional setup after loading the view.
    }

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

    public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?{
        guard let viewControllerIndex = VCArr.index(of: viewController) else{
            return nil
        }
        let previousIndex = viewControllerIndex-1
        
        guard previousIndex >= 0 else{
            return VCArr.last
        }
        
        guard VCArr.count > previousIndex else {
            return nil
        }
        
        return VCArr[previousIndex]
    }
    

    public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?{
        guard let viewControllerIndex = VCArr.index(of: viewController) else{
            return nil
        }
        let nextIndex = viewControllerIndex+1
        
        guard nextIndex < VCArr.count else{
            return VCArr.first
        }
        
        guard VCArr.count > nextIndex else {
            return nil
        }
        
        return VCArr[nextIndex]
    }
    

    public func presentationCount(for pageViewController: UIPageViewController) -> Int{
        return VCArr.count
    }// The number of items reflected in the page indicator.
    
    public func presentationIndex(for pageViewController: UIPageViewController) -> Int{
        guard let firstViewController = viewControllers?.first,
            let firstViewControllerIndex = VCArr.index(of: firstViewController) else{
            return 0
        }
        return firstViewControllerIndex
    }// The selected item reflected in the page indicator.



}

Navigation Controller第一次使用

1. 在Story Board拉入一個新的Navigation Controller

2. 刪掉多的Table View

3. Navigation Controller連接到第一頁, 選root view ...

4. 刪掉原本的init view controller

5. Navigation Controller設定為init view controller