facebook twitter hatena line email

Ios/swift/外部ライブラリ/Eureka

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

Eurekaとは

swiftの設定画面用のライブラリ

公式

https://github.com/xmartlabs/Eureka

インストール

vi podfile
source 'https://github.com/CocoaPods/Specs.git'  
platform :ios, '8.0'  
use_frameworks!
pod 'Eureka', '~> 1.6'
$ pod install

サンプル

import Eureka
class MyFormViewController: FormViewController {
   override func viewDidLoad() {
       super.viewDidLoad()
       form +++ Section("Section1")
           <<< TextRow(){ row in
               row.title = "Text Row"
               row.placeholder = "Enter text here"
           }.onChange{row in
               print("text " + String(row.value))
               // 空だとnilが入ってくる
                   if row.value != nil {
                       self._value = row.value!
                   } else {
                       self._value = ""
                   }
           }
           <<< PhoneRow(){
               $0.title = "Phone Row"
               $0.placeholder = "And numbers here"
           }.onChange{row in
                print("phone " + String(row.value))
           }
           +++ Section("Section2")
           <<< DateRow(){
               $0.title = "Date Row"
               $0.value = NSDate(timeIntervalSinceReferenceDate: 0)
           }.onChange{row in
                print("date " + String(row.value))
           }
           <<< ButtonRow(){
               $0.title = "Button1"
           }.onCellSelection{row in
                   print("click")
           }
           <<< ActionSheetRow<String>() {
               $0.title = "ActionSheetRow"
               $0.selectorTitle = "Pick a number"
               $0.options = ["One","Two","Three"]
               $0.value = "Two"    // initially selected
           }.onChange{row in
                print("date " + String(row.value))
           }
   }
}

コールバック

onChange() セルの値が変わった時に呼ばれる
onCellSelection() セルをタップした時に呼ばれる
cellSetup() セルの初期生成時に呼ばれる
cellUpdate() セルが表示される度に呼ばれる
onCellHighlight() セルがファーストレスポンダーになった時に呼ばれる
onCellUnHighlight() セルがファーストレスポンダーではなくなった時に呼ばれる
onExpandInlineRow() インライン型のセルが広がる前に呼ばれる
onCollapseInlineRow() インライン型のセルが閉じる前に呼ばれる
onPresent() 他のViewControllerへ遷移する前に呼ばれる

参考:http://blog.personal-factory.com/2015/12/29/eureka-tutorial/