CaliCastle / PopMenu

A fully customizable popup style menu for iOS 😎
https://popmenu.cali.so
MIT License
1.6k stars 182 forks source link

How to use PopMenu with TableView #18

Open phracek opened 5 years ago

phracek commented 5 years ago

✔️ Issue Checklist

✍🏻 Issue Description

Your PopMenu is interesting and I would like to use it in my project. I have table view with cell and I would like to use your PopMenu which contains something like Favorites, and other things, like showing details what is mentioned in cell. If user selects Favorites, then cell is marked with star like marked. Unfortunately, I am a dummy user and I am not able to find out a way how to refresh table view cell, so that after pressing on Favorites, table view is rendered.

Would it be possible to add a some notes also to your README.md file. It would be more understandable from my point of view.

Can you help me what I have to do? Thanks.

💻 Environment

phracek commented 5 years ago

My code in tableview is following:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(indexPath)
        print(indexPath.row)
        let action1 = PopMenuDefaultAction(title: "Add / Remove from favorites", didSelect: {action in
            let row_id = self.paragraphRowData[indexPath.row].id
            print(row_id)
            if self.get_favorites(id: row_id) == false {
                print("Add to favorites")
                self.paragraphRowData[indexPath.row].fav = true
                self.favorites.append(row_id)
            }
            else
            {
                print("remove")
                self.paragraphRowData[indexPath.row].fav = false
                if let index = self.favorites.firstIndex(of: row_id) {
                    self.favorites.remove(at: index)
                }
            }
            print(self.favorites)
            self.userDefaults.set(self.favorites, forKey: "Favorites")
            self.tableView.beginUpdates()
            self.tableView.reloadData()
            self.tableView.endUpdates()
        })
        let action2 = PopMenuDefaultAction(title: "Show references", didSelect: {action in
            print("Paragraphs")
        })
        let manager = PopMenuManager.default
        manager.addAction(action1)
        manager.addAction(action2)
        manager.present(on: self)
}

But for now I still getting the same row_id, when application is run. My code is available on GitHub https://github.com/phracek/Katechismus_katolicke_cirkve_iOS/blob/master/KatechismusKatolickeCirkve/KatechismusKatolickeCirkve/Controllers/ParagraphTableViewController.swift#L134

CaliCastle commented 5 years ago

@phracek thanks for the details, I'll look into it

ins0u commented 4 years ago

Same problem :/

I still getting the same row_id in my app too..

Do you know why ?


Solution :

Store your value (row_id) in a class variable and use it everywhere..

it worked for me :)