QuickDialog可以幫助開發者快速創建復雜的表單,實現包括登錄界面在內的各種樣式的TableView輸入界面,此外,還可以創建帶有多個文本域的表格及項目。
QuickDialog通過對數據元素的峰值封裝,根據不同元素的使用來簡化UITableView的使用。
為了使用QuickDialog你必須知道三個不同的類:
QuickDialogController——是UITableViewController的子類,用于顯示對話框在你的應用中你可能會創建這個類的子類來顯示。
QRootElement——一個對話框的根元素,sections與cells的容器,用戶顯示用戶數據。每一個QuickDialogController一次只可以顯示一RootElement。可以包含其他的rootElement的。
QElement——一個element映射一個UItableViewCell,盡管它包括更多的功能,像能夠從cell中讀取值和有多個類型。QuickDialog也提供了多種內建element type,像 ButtonElement 和 EntryElement,但你也能夠創建自己的element。
一 關于Elements
* QuickDialog 提供了可以應用于app的很多不同elements。
* QLabelElement: 簡單的內建鍵值對映射
* QBadgeElement: 想label cell,但值是作為一個徽標顯示的
* QBooleanElement: 顯示一個開關
* QButtonElement: 在中間顯示一個標題想一個button一樣
*QDateTimeElement:允許你編輯dates,time,或者date + time值。編輯發生在新樸實出來的viwController中。
* QEntryElement: 輸入字段,允許你收集用戶的信息。可以自動擴展。
* QDecimalElement: 非常想一個可輸入的field,但是只允許輸入數字。可以預定義輸入的精度。
* QFloatElement: 顯示一個滑動欄
* QMapElement: 當被選中時,顯示一個有location的全屏地圖,需要經緯度值。
* QRadioElement:允許用戶從多個可利用的選項中選擇一個。自動push一個新的有已被選中的item的table。
* QTextElement: 可提供字體渲染的自由文本
* QWebElement: push一個在element中定義URL的簡單瀏覽頁面。 `
下面看下QuickDialog中element的繼承關系:
二 關于Sections
- sections 是一個簡單的elements分組,默認情況下有一下幾種特性:
- title/footer:頁眉/頁腳部分顯示為簡單的字符串
- headerView/footerView:這種情況下,Views可以替換掉titles的顯示,可以簡單的顯示圖片或自定義的Views
關于sections的結構圖如下:
* QRadioSection:內聯的顯示多個選項,而不是到另一個UIViewController中。
* QSortingSection:自動在sections中對cells進行排序。
三 關于自定義的UITableViewCell
在QuickDialog中自定義了一部分的UITableViewCell,來對應于定義的elements。其結構如下:
四 關于QuickDialog的使用
集成QucikDialog到項目中\n 最簡單的方法是把quickDialog作為git子模塊添加到你的現有工程中,然后作為一部分導入到project中。 Terminal:
cd your-project-location git submodule add git@github.com:escoz/QuickDialog.git
這種方法是從github中自動copy的,因此你在將來可以方便的更新。
在XCode中: 打開已存在的project(或者創建個新的) 把從github分支上下載QuickDialog.xcodeproj拖拽到你的工程中(root或framework下) 在工程配置下:
* 在Build Phases,添加QuickDialog(the lib, not the example app)作為目標依賴
* 在Build Phases->Link binary with libraries下,添加這兩個庫:MapKit.framework and CoreLocation.framework
* 在Link binary with libraries下添加這個QuickDialog.a靜態庫
* 在你的prefix.pch未見中,添加#import
* 在你的工程配置中的“Build Settings”下 本地的"User Header Search Paths"設置,并設置值為"${PROJECT_DIR}/QuickDialog"(包括引號!)并且勾選"Recursive"選項。
* Debug值應當已經被設置,如果沒有,修改它。
* 本地的 “Always Search User Paths”設置為YES
* 最后找到 “Other Linker Flags”選擇項,并且添加至-ObjC
***OK,that should be all there is. Here’s how you can create and display your first dialog from inside another UIViewController:
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Hello World";
root.grouped = YES;
QSection *section = [[QSection alloc] init];
QLabelElement *label = [[QLabelElement alloc] initWithTitle:@"Hello" Value:@"world!"];
[root addSection:section];
[section addElement:label];
UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];
The code above will create the form below:
五:QuickDialog的數據交互
由于QuickDialog是通過對數據的封裝實現對UI的控制的,所以要獲得數據的話有兩種方式,一種是直接通過elements的屬性獲取,一種是通過bind的對應鍵值來使用fetchValueUsingBindingsIntoObject來拉去的。這樣的話必須bind中的key與放入對象的attribute的名稱要一直,否則會拉去不到crash。
對QuickDialogTableView的點擊事件可以直接設置block來進行控制,這樣較容易控制的。