Closed wejn closed 10 years ago
Just in case anyone runs into the same problem till there's official fix... this:
# remove following monkeypatch when ProMotion issue #233 is resolved
class ProMotion::Table
alias_method :delete_row_buggy, :delete_row
def delete_row(index_paths, animation = nil)
index_paths = [index_paths] if index_paths.kind_of?(NSIndexPath)
delete_row_buggy(index_paths, animation)
end
end
will make the problem go away.
Looks good to me. Can you submit a PR to master?
Sent.
Hello,
I have apparently the same issue.
When I add sugarcube in my gem list, deleting from a table ends up with "undefined method `section' for 0:Fixnum (NoMethodError)" Removing sugarcube, no error when deleting. With sugarcube and wejn's fix, no issue.
Is it something you're aware of ?
Looks like that fix disappeared in the PM 2.0 refactor. Added it back in (PR open).
:thumbsup:
I have same problem with ProMotion (2.5.0) sugarcube (3.3.7)
i added a monkey patch for temporary fix
The fix is work, but getting wrong index (0).
module ProMotion
class TableData
def cell(params={})
if params.is_a?(Hash) && params[:index_path]
if params[:index_path].is_a?(Fixnum)
params[:index_path] = [0, params[:index_path]].nsindexpath
end
end
params = index_path_to_section_index(params)
table_section = params[:unfiltered] ? self.data[params[:section]] : self.section(params[:section])
c = table_section[:cells].at(params[:index].to_i)
set_data_cell_defaults(c)
end
end
end
I cannot found 'cell' called from where.
That's weird.
Hi,
I've found out that deleting rows fails when
sugarcube
gem is included.The trace I'm getting is:
which doesn't make much sense, as there shouldn't be Fixnum passed as index_path to
PM::TableData#cell(params={})
.Through experimenting I found out that the following line in
delete_row
is the offender:Changing it to:
resolves the issue for me.
This auto-conversion of
NSIndexPath
toArray
(through the fact sugarcube suppliesnsindex.to_a
) makes anyArray(index_path)
construct potentially unsafe.Any take as to how to resolve this the proper way? (for now I've monkeypatched PM source for myself)