diff --git a/README.md b/README.md index 3e46306..3935676 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ director.appendSections(sectionBuilder) ### Cell actions +Tablet provides a chaining approach to handle actions from your cells: + ```swift import Tablet @@ -84,9 +86,9 @@ import Tablet class UserTableViewCell : UITableViewCell { - @IBAction func shareButtonClicked(sender: UIButton) { + @IBAction func buttonClicked(sender: UIButton) { - Action(key: "action_key", sender: self).trigger() + Action(key: "action_key", sender: self, userInfo: nil).trigger() } } ``` @@ -94,7 +96,7 @@ And receive this actions with your row builder: ```swift import Tablet -let rowBuilder = TableRowBuilder(items: users, id: "reusable_id") +let rowBuilder = TableRowBuilder(items: users, id: "reusable_id") .action(.click) { data in } diff --git a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj index 1c74af6..3c3b98c 100644 --- a/TabletDemo/TabletDemo.xcodeproj/project.pbxproj +++ b/TabletDemo/TabletDemo.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ DAB7EB321BEF787300D2AD5E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DAB7EB311BEF787300D2AD5E /* Assets.xcassets */; }; DAB7EB351BEF787300D2AD5E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */; }; DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */; settings = {ASSET_TAGS = (); }; }; + DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */; settings = {ASSET_TAGS = (); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +25,7 @@ DAB7EB341BEF787300D2AD5E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; DAB7EB361BEF787300D2AD5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DAB7EB3D1BEF78A400D2AD5E /* Tablet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tablet.swift; sourceTree = ""; }; + DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableTableViewCell.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,6 +61,7 @@ children = ( DAB7EB2A1BEF787300D2AD5E /* AppDelegate.swift */, DAB7EB2C1BEF787300D2AD5E /* ViewController.swift */, + DAB7EB3F1BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift */, DAB7EB2E1BEF787300D2AD5E /* Main.storyboard */, DAB7EB311BEF787300D2AD5E /* Assets.xcassets */, DAB7EB331BEF787300D2AD5E /* LaunchScreen.storyboard */, @@ -148,6 +151,7 @@ files = ( DAB7EB2D1BEF787300D2AD5E /* ViewController.swift in Sources */, DAB7EB3E1BEF78A400D2AD5E /* Tablet.swift in Sources */, + DAB7EB401BEFD07E00D2AD5E /* ConfigurableTableViewCell.swift in Sources */, DAB7EB2B1BEF787300D2AD5E /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 7767223..daf4a1a 100644 Binary files a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TabletDemo/TabletDemo/AppDelegate.swift b/TabletDemo/TabletDemo/AppDelegate.swift index 5453072..69cc0e6 100644 --- a/TabletDemo/TabletDemo/AppDelegate.swift +++ b/TabletDemo/TabletDemo/AppDelegate.swift @@ -12,35 +12,4 @@ import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - // Override point for customization after application launch. - return true - } - - func applicationWillResignActive(application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - -} - +} \ No newline at end of file diff --git a/TabletDemo/TabletDemo/Base.lproj/LaunchScreen.storyboard b/TabletDemo/TabletDemo/Base.lproj/LaunchScreen.storyboard index 2e721e1..ffacbd6 100644 --- a/TabletDemo/TabletDemo/Base.lproj/LaunchScreen.storyboard +++ b/TabletDemo/TabletDemo/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + diff --git a/TabletDemo/TabletDemo/Base.lproj/Main.storyboard b/TabletDemo/TabletDemo/Base.lproj/Main.storyboard index 3a2a49b..98f93de 100644 --- a/TabletDemo/TabletDemo/Base.lproj/Main.storyboard +++ b/TabletDemo/TabletDemo/Base.lproj/Main.storyboard @@ -1,13 +1,14 @@ - + - + + - + @@ -15,11 +16,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift new file mode 100644 index 0000000..3d96de5 --- /dev/null +++ b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift @@ -0,0 +1,33 @@ +// +// ConfigurableTableViewCell.swift +// TabletDemo +// +// Created by Max Sokolov on 08/11/15. +// Copyright © 2015 Tablet. All rights reserved. +// + +import UIKit + +let kConfigurableTableViewCellButtonClickedAction = "button_clicked" + +class ConfigurableTableViewCell: UITableViewCell, ConfigurableCell { + + typealias Item = String + + @IBOutlet weak var button: UIButton! + + static func reusableIdentifier() -> String { + + return "configurable_cell" + } + + func configureWithItem(item: Item) { + + button.setTitle("Button \(item)", forState: .Normal) + } + + @IBAction func buttonClicked(sender: UIButton) { + + Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).trigger() + } +} \ No newline at end of file diff --git a/TabletDemo/TabletDemo/ViewController.swift b/TabletDemo/TabletDemo/ViewController.swift index 327c880..8dd2ca5 100644 --- a/TabletDemo/TabletDemo/ViewController.swift +++ b/TabletDemo/TabletDemo/ViewController.swift @@ -10,16 +10,32 @@ import UIKit class ViewController: UIViewController { + @IBOutlet weak var tableView: UITableView! + var tableDirector: TableDirector! + override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. + + tableDirector = TableDirector(tableView: tableView) + + let rowBuilder = TableRowBuilder(items: [1, 2, 3, 4], id: "cell") + .action(.configure) { data in + + data.cell.textLabel?.text = "\(data.item)" + } + + let configurableRowBuilder = TableConfigurableRowBuilder(items: ["5", "6", "7", "8"]) + .action(kConfigurableTableViewCellButtonClickedAction) { data in + + print("custom action indexPath: \(data.indexPath), item: \(data.item)") + } + .action(.click) { data in + + print("custom action indexPath: \(data.indexPath), item: \(data.item)") + } + + let sectionBuilder = TableSectionBuilder(headerTitle: "Tablet", footerTitle: "Deal with table view like a boss.", rowBuilders: [rowBuilder, configurableRowBuilder]) + + tableDirector.appendSection(sectionBuilder) } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - -} - +} \ No newline at end of file