Reputation: 17912
I have filter tableView, this is expandable tableView. When user click on button in IndexPath [2,0] 3rd section 1st row i want to create on more single select tableView in that position. For that I'm getting that btn x and y position and I'm creating transparent view, on that I'm creating tableView. But position of that new tableView is not in proper.
How to create new tableView in specific position when user tapped in tableView indexPath [2,0].
Upvotes: 0
Views: 93
Reputation: 698
Assuming you want to show your "transparent view" and "single select table view" on parent view.
Create a delegate for your controller class to get current cell view
protocol MyCellDelegate: class {
func didTapButton(forCell cell: MyTableViewCell)
}
class MyTableViewCell: UITableViewCell {
weak var delegate: MyCellDelegate?
@IBAction func didTapButton(_ sender: UIButton) {
delegate?.didTapButton(forCell: self)
}
}
class MyViewController: UIViewController, UITableViewDataSource, MyCellDelegate {
//...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell
cell.delegate = self
}
func didTapButton(forCell cell: MyTableViewCell) {
//
}
}
Create frame for transparent view inside delegate method and add it (which will contain your single select table view)
func didTapButton(forCell cell: MyTableViewCell) {
let buttonFrame = cell.convert(cell.myButton.frame, to: self.view)
let transparentView = UIView(frame: CGRect(x: buttonFrame.origin.x,
y: buttonFrame.maxY,
width: buttonFrame.width,
height: 128))
let singleSelectTableView = UITableView(frame: CGRect(origin: .zero, size: transparentView.frame.size))
// setup table view data source code here (make a separate class)
transparentView.addSubview(singleSelectTableView)
self.view.addSubview(transparentView)
}
Upvotes: 1