diff --git a/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 6150352..ecbfcfa 100644 Binary files a/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/Tablet.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index d681cda..d3a356b 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -71,7 +71,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) { let builder = builderAtIndexPath(indexPath) - builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: action.userInfo) + builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1, userInfo: notification.userInfo) } } diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 970989e..59afd53 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -95,10 +95,10 @@ public class TableRowBuilder : RowBuilder { // MARK: Triggers - public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]? = nil) -> AnyObject? { + public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { if let action = actions[actionType.key] { - return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex)) + return action.invoke(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo)) } return nil } @@ -144,14 +144,14 @@ public class TableConfigurableRowBuilder AnyObject? { + public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { switch actionType { case .configure: (cell as? C)?.configureWithItem(items[itemIndex]) default: break } - return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex) + return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo) } } diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index 0e71508..3a4eaa0 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -57,13 +57,15 @@ public class ActionData { public let item: I public let itemIndex: Int public let indexPath: NSIndexPath - - init(cell: C?, indexPath: NSIndexPath, item: I, itemIndex: Int) { - + public let userInfo: [NSObject: AnyObject]? + + init(cell: C?, indexPath: NSIndexPath, item: I, itemIndex: Int, userInfo: [NSObject: AnyObject]?) { + self.cell = cell self.indexPath = indexPath self.item = item self.itemIndex = itemIndex + self.userInfo = userInfo } } @@ -91,7 +93,7 @@ public class Action { public func invoke() { - NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self) + NSNotificationCenter.defaultCenter().postNotificationName(TabletNotifications.CellAction, object: self, userInfo: userInfo) } } diff --git a/Tablet/Tablet.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/Tablet/Tablet.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 1d9a3e2..7e3b132 100644 Binary files a/Tablet/Tablet.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/Tablet/Tablet.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Tablet/Tablet.xcodeproj/xcuserdata/maxsokolov.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Tablet/Tablet.xcodeproj/xcuserdata/maxsokolov.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/Tablet/Tablet.xcodeproj/xcuserdata/maxsokolov.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/Tests/TabletTests.swift b/Tests/TabletTests.swift index a578fcd..4d5c7b9 100644 --- a/Tests/TabletTests.swift +++ b/Tests/TabletTests.swift @@ -39,6 +39,9 @@ struct TestData { struct TestTableViewCellOptions { static let ReusableIdentifier: String = "ReusableIdentifier" + static let CellAction: String = "CellAction" + static let CellActionUserInfoKey: String = "CellActionUserInfoKey" + static let CellActionUserInfoValue: String = "CellActionUserInfoValue" static let EstimatedHeight: Float = 255 } @@ -57,6 +60,10 @@ class TestTableViewCell: UITableViewCell, ConfigurableCell { func configureWithItem(item: Item) { textLabel?.text = item.title } + + func raiseAction() { + Action(key: TestTableViewCellOptions.CellAction, sender: self, userInfo: [TestTableViewCellOptions.CellActionUserInfoKey: TestTableViewCellOptions.CellActionUserInfoValue]).invoke() + } } class TabletTests: XCTestCase { @@ -134,6 +141,7 @@ class TabletTests: XCTestCase { testController.view.hidden = false testController.tableDirector += section + testController.tableView.reloadData() XCTAssertTrue(testController.tableView.dataSource?.numberOfSectionsInTableView?(testController.tableView) == 1, "Table view should have a section") XCTAssertTrue(testController.tableView.dataSource?.tableView(testController.tableView, numberOfRowsInSection: 0) == 1, "Table view should have certain number of rows in a section") @@ -154,12 +162,39 @@ class TabletTests: XCTestCase { testController.view.hidden = false testController.tableDirector += section + testController.tableView.reloadData() XCTAssertTrue(testController.tableView.dataSource?.numberOfSectionsInTableView?(testController.tableView) == 1, "Table view should have a section") XCTAssertTrue(testController.tableView.dataSource?.tableView(testController.tableView, numberOfRowsInSection: 0) == 1, "Table view should have certain number of rows in a section") XCTAssertTrue(testController.tableView.delegate?.tableView?(testController.tableView, viewForHeaderInSection: 0) == sectionHeaderView) XCTAssertTrue(testController.tableView.delegate?.tableView?(testController.tableView, viewForFooterInSection: 0) == sectionFooterView) + } + + func testRowBuilderCustomActionInvokedAndSentUserInfo() { + + let expectation = expectationWithDescription("cell action") + + let row = TableConfigurableRowBuilder(items: [TestData(title: "title")]) + .action(TestTableViewCellOptions.CellAction) { data -> Void in + + XCTAssertNotNil(data.cell, "Action data should have a cell") + XCTAssertNotNil(data.userInfo, "Action data should have a user info dictionary") + XCTAssertTrue(data.userInfo?[TestTableViewCellOptions.CellActionUserInfoKey] as? String == TestTableViewCellOptions.CellActionUserInfoValue, "UserInfo should have correct value for key") + + expectation.fulfill() + } + + testController.view.hidden = false + testController.tableDirector += row + testController.tableView.reloadData() + let cell = testController.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0)) as? TestTableViewCell + + XCTAssertNotNil(cell, "Cell should exists and should be TestTableViewCell") + + cell?.raiseAction() + + waitForExpectationsWithTimeout(1.0, handler: nil) } } \ No newline at end of file