EurekaCommunity / SplitRow

A row for Eureka to put two rows side by side into the same UITableViewCell
MIT License
56 stars 27 forks source link

Indexpath of row #18

Closed tarikstafford closed 6 years ago

tarikstafford commented 6 years ago

Hey there,

Trying to fetch the indexpath of the row to validate an error of the right row. Unsure of how to add another row below it.

Thx

mats-claassen commented 6 years ago

row.indexPath() returns the IndexPath of the row in the form. You could then use section.insert(at: index + 1) with the section of that row.

tarikstafford commented 6 years ago

@mats-claassen from the split row (rightRow in this case) indexPath is undefined.

onRowValidationChanged{cell, row in
                        let rowIndex = row.indexPath!.row

ie. this crashes.

mats-claassen commented 6 years ago

You are right, as that row is not added to a section itself. If you have a reference to its parent (SplitRow) row then you can use its indexPath.

If not then I would get the SplitRow using form.row(by: tag) and use its indexPath.

marbetschar commented 6 years ago

@tarikstafford you might want to use the indexPath of the splitRow itself. Make sure to use a named variable in the rows init to use its value in the embedded rows:

SplitRow<TextRow,TextRow>{ splitRow in splitRow.rowRight = TextRow{ $0.onRowValidationChanged{ cell, row in //splitRow.indexPath } }

tarikstafford commented 6 years ago

hey @marbetschar & @mats-claassen,

Mats solution works perfectly. Cheers.