Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get indexPath for the customizeTableViewCell #42

Open
sahibhussain opened this issue Jul 17, 2019 · 3 comments
Open

How to get indexPath for the customizeTableViewCell #42

sahibhussain opened this issue Jul 17, 2019 · 3 comments

Comments

@sahibhussain
Copy link

sahibhussain commented Jul 17, 2019

i want to add image for each cell in tableview of suggestion-row i can add a single image by calling cell.imageView but if i want to put different image in each cell please Help

           row.cell.customizeTableViewCell = { (cell, index) in
                print(row.cell.tableView?.indexPath(for: cell) ?? "not found")
                print(index)
                cell.imageView?.image = UIImage(named: "correct.png")
//                let index = cell.ind
            }

i even edited the class to insert index but for some reason it print 1 everytime

@sahibhussain
Copy link
Author

i called it in cellUpdate, cellHighlighted, basic cell setup i just get the same result everytime

@sahibhussain
Copy link
Author

sahibhussain commented Jul 17, 2019

i manage to get a workaround but it may fail sometime if anyone have a better option please do let me know.
for now this is what i did
`
row.cell.customizeTableViewCell = { (cell) in

            if let text = cell.textLabel!.text {
                var i = 0
                for j in 0..<self.options.count {
                    let val = self.options[j]
                    if val == text {
                        i = j
                        break
                    }
                }
                
                cell.imageView?.image = UIImage(named: "\(i)")
                
            }
        }

`

@mats-claassen
Copy link
Member

Hi @sahibhussain.
You can use any type conforming to SuggestionValue as the value of this row. This means you can create a class or struct containing a text and image variables and add options with this type to the row. In that case you only have to get the option for a given index and access its image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants