Merge pull request #192 from clearsightstudio/fix-tableview-cell-delete

Fix tableview cell delete
This commit is contained in:
Jamon Holmgren
2013-07-02 19:41:58 -07:00
3 changed files with 30 additions and 7 deletions

View File

@@ -106,6 +106,7 @@ module ProMotion
index_paths = Array(index_paths)
index_paths.each do |index_path|
cell_deleted(@promotion_table_data.cell(index_path: index_path)) if self.respond_to?("cell_deleted:")
@promotion_table_data.delete_cell(index_path: index_path)
end
table_view.deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)
@@ -196,9 +197,7 @@ module ProMotion
data_cell = @promotion_table_data.cell(index_path: index_path)
case data_cell[:editing_style]
when nil
UITableViewCellEditingStyleNone
when :none
when nil, :none
UITableViewCellEditingStyleNone
when :delete
UITableViewCellEditingStyleDelete
@@ -211,7 +210,7 @@ module ProMotion
def tableView(table_view, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
if editing_style == UITableViewCellEditingStyleDelete
delete_cell(index_path)
delete_row(index_path)
end
end
@@ -228,7 +227,7 @@ module ProMotion
def deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)
PM.logger.warn "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'."
delete_cell(index_paths, animation)
delete_row(index_paths, animation)
end
module TableClassMethods

View File

@@ -49,6 +49,26 @@ describe "ProMotion::TestTableScreen functionality" do
end
end
# TODO: Why is it so complicated to find the delete button??
it "should use editing_style to delete the table row" do
@controller.tableView(@controller.tableView, numberOfRowsInSection:0).should == 6
@controller.cell_was_deleted.should != true
flick("Just another deletable blank row", :to => :left)
wait 0.25 do
# Tap the delete button
view('Just another deletable blank row').superview.superview.subviews.each do |subview|
if subview.class == UITableViewCellDeleteConfirmationControl
tap subview
wait 0.25 do
@controller.tableView(@controller.tableView, numberOfRowsInSection:0).should == 5
@controller.cell_was_deleted.should == true
end
end
end
end
end
it "should call a method when the switch is flipped" do
@controller.scroll_to_bottom
tap "switch_1"

View File

@@ -1,6 +1,6 @@
class TestTableScreen < ProMotion::TableScreen
attr_accessor :tap_counter
attr_accessor :tap_counter, :cell_was_deleted
def promotion_table_data
@promotion_table_data
@@ -17,7 +17,7 @@ class TestTableScreen < ProMotion::TableScreen
{ title: "Increment", action: :increment_counter_by, arguments: {number: 3} },
{ title: "Add New Row", action: :add_tableview_row },
{ title: "Delete the row below", action: :delete_cell, arguments: {section: 0, row:3} },
{ title: "Just another blank row" },
{ title: "Just another deletable blank row", editing_style: :delete },
{ title: "Delete the row below with an animation", action: :delete_cell, arguments: {animated: true, section: 0, row:5 } },
{ title: "Just another blank row" }
]
@@ -86,6 +86,10 @@ class TestTableScreen < ProMotion::TableScreen
end
end
def cell_deleted(cell)
self.cell_was_deleted = true
end
def increment_counter
self.tap_counter = self.tap_counter + 1
end