actionWithReturnValue

This commit is contained in:
Max Sokolov 2015-11-10 20:20:27 +03:00
parent cc69a5e8d7
commit 5b639c4483
5 changed files with 139 additions and 1 deletions

View File

@ -33,6 +33,9 @@ public enum ActionType : String {
case deselect = "_deselect"
case configure = "_configure"
case willDisplay = "_willDisplay"
case shouldHighlight = "_shouldHighlight"
}
public struct ActionData<I, C> {
@ -99,6 +102,7 @@ public protocol ReusableRowBuilder {
public class TableRowBuilder<I, C where C: UITableViewCell> : ReusableRowBuilder {
public typealias TableRowBuilderActionBlock = (data: ActionData<I, C>) -> Void
public typealias TableRowBuilderReturnValueActionBlock = (data: ActionData<I, C>) -> AnyObject
private var actions = Dictionary<String, TableRowBuilderActionBlock>()
private var items = [I]()
@ -149,6 +153,18 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : ReusableRowBuilder
return self
}
public func action(key: ActionType, action: TableRowBuilderReturnValueActionBlock) -> Self {
return self
}
public func actionWithReturnValue(key: ActionType, action: (ActionData<I, C>) -> Bool) -> Self {
return self
}
// MARK: Triggers
public func triggerAction(key: String, cell: UITableViewCell, indexPath: NSIndexPath, itemIndex: Int) -> Bool {
@ -383,4 +399,9 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
triggerAction(.willDisplay, cell: cell, indexPath: indexPath)
}
public func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
}

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DAB7EB261BEF787300D2AD5E"
BuildableName = "TabletDemo.app"
BlueprintName = "TabletDemo"
ReferencedContainer = "container:TabletDemo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DAB7EB261BEF787300D2AD5E"
BuildableName = "TabletDemo.app"
BlueprintName = "TabletDemo"
ReferencedContainer = "container:TabletDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DAB7EB261BEF787300D2AD5E"
BuildableName = "TabletDemo.app"
BlueprintName = "TabletDemo"
ReferencedContainer = "container:TabletDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DAB7EB261BEF787300D2AD5E"
BuildableName = "TabletDemo.app"
BlueprintName = "TabletDemo"
ReferencedContainer = "container:TabletDemo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>TabletDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>DAB7EB261BEF787300D2AD5E</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@ -30,9 +30,13 @@ class ViewController: UIViewController {
print("custom action indexPath: \(data.indexPath), item: \(data.item)")
}
.action(.click) { data in
print("custom action indexPath: \(data.indexPath), item: \(data.item)")
}
.action(.shouldHighlight) { _ in
return false
}
let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder])