SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

Dynamic table view is not working with Segue #358

Closed D2Jgs closed 4 years ago

D2Jgs commented 4 years ago

I created a dynamic table view using the example of the bottom message segue you provided, but it does not work.

The "override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell " never gets called.

Is it not supposed to work with dynamic table views?

D2Jgs commented 4 years ago

I found the solution for the problem in one of the closed issues.

it was giving the background view a height.

D2Jgs commented 4 years ago

How can I add a keyboardTrackingView in such a scenario?

I am using a search bar in the bottom message viewcontroller.

wtmoose commented 4 years ago

You can an assign the keyboardTrackingView property on the segue to get basic keyboard avoidance.

D2Jgs commented 4 years ago

Could you please help me figure out where and how to access that property.

Below is code for the bottom message segue :-

class SwiftMessagesBottomSegue: SwiftMessagesSegue {
    override public  init(identifier: String?, source: UIViewController, destination: UIViewController) {
        super.init(identifier: identifier, source: source, destination: destination)
        messageView.backgroundHeight = 200
        configure(layout: .bottomMessage)
    }
}

Below is the tableView Controller being called

class SearchTableViewController: UITableViewController {

    let test : [String] = ["Test1","Test2","Test3","Test1","Test2","Test3","Test1","Test2","Test3","Test1","Test2","Test3"]

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.separatorStyle = .none
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return test.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "testTableCell", for: indexPath) as! searchTableViewCell

        cell.textDataLabel.text = test[indexPath.row]

        return cell
    }

Thank you.

wtmoose commented 4 years ago
class SwiftMessagesBottomSegue: SwiftMessagesSegue {
    override public  init(identifier: String?, source: UIViewController, destination: UIViewController) {
        super.init(identifier: identifier, source: source, destination: destination)
        messageView.backgroundHeight = 200
        configure(layout: .bottomMessage)
        keyboardTrackingView = KeyboardTrackingView()
    }
}
wtmoose commented 4 years ago

Please try to use proper Markdown format for your code. I edited your post to make it readable.

D2Jgs commented 4 years ago

There is no such property as keyboardTrackingView in SwiftMessagesSegue. It shows the error "Use of unresolved identifier 'keyboardTrackingView'"

D2Jgs commented 4 years ago

Is it only available for swift 5?

If that is the case then it is fine because I am working on Swift 4.2.

wtmoose commented 4 years ago

It was added in SwiftMessages 7.0.0, which is Swift 5. Sorry.

D2Jgs commented 4 years ago

Ok. No problem. Thanks anyways