[Swift通天遁地]2、表格表單-(14)實時調整表單元素的激活和失效

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-ylnqeipm-ko.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

目錄:[Swift]通天遁地Swiftgit

本文將演示如何激活或使表單的區域失效。github

在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】swift

如今開始編寫代碼,實現激活或使表單的區域失效。微信

 1 import UIKit
 2 //首先在當前類文件中,
 3 //引入以及安裝的第三方類庫
 4 import Eureka
 5 
 6 //修改當前視圖控制器類的父類的名稱
 7 class ViewController: FormViewController {
 8     
 9     override func viewDidLoad() {
10         super.viewDidLoad()
11         
12         //往表單中添加一個段落
13         form = Section()
14             //在段落中添加一個分段行
15             <<< SegmentedRow<String>("segments")
16             {
17                 //設置該行的選項
18                 $0.options = ["Enabled", "Disabled"]
19                 //設置該行的默認值
20                 $0.value = "Disabled"
21             }
22             //在段落中添加一個文本行
23             <<< TextRow()
24             {
25                 //設置該行的標題文字
26                 $0.title = "choose enabled, disable above..."
27                 //並設置它的失效屬性,當分段的值爲失效時,該文本行也將失效。
28                 $0.disabled = "$segments = 'Disabled'"
29             }
30             //在段落中添加一個Switch行
31             <<< SwitchRow("Disable Next Section?")
32             {
33                 //設置該行的標題文字
34                 $0.title = $0.tag
35                 //並設置它的失效屬性,當分段的值爲失效時,該Switch行也將失效。
36                 $0.disabled = "$segments = 'Disabled'"
37             }
38             //添加一個新的段落
39             +++ Section()
40             //在段落中添加一個文本行
41             <<< TextRow()
42             {
43                 //設置該行的標題文字
44                 $0.title = "Gonna be disabled soon.."
45                 //並設置它的失效狀態,
46                 //根據上一個段落中的開關行的狀態,來決定本行的失效狀態。
47                 $0.disabled = Eureka.Condition.function(["Disable Next Section?"], { (form) -> Bool in
48                     let row: SwitchRow! = form.rowBy(tag: "Disable Next Section?")
49                     return row.value ?? false
50                 })
51             }
52             
53             //添加一個新的段落
54             +++ Section()
55              //在段落中添加一個分段行
56             <<< SegmentedRow<String>()
57             {
58                 //設置該行的選項
59                 $0.options = ["Always Disabled"]
60                 //並設置它的失效狀態
61                 $0.disabled = true
62             }
63     }
64 
65     override func didReceiveMemoryWarning() {
66         super.didReceiveMemoryWarning()
67         // Dispose of any resources that can be recreated.
68     }
69 }
相關文章
相關標籤/搜索