Closed ghost closed 8 years ago
If you try to make the class :) For example,
class TablePopover: NSObject {
var tableView: UITableView!
var popover: Popover = Popover()
init(tableFrame: CGRect) {
self.tableView= UITableView(frame: tableFrame)
}
func show(fromView: UIView, inView: UIView) {
self.tableView.delegate = self
self.tableView.dataSource = self
self.popover.show(self.tableView, fromView: fromView, inView: inView)
}
}
extension TablePopover: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
}
}
extension TablePopover: UITableViewDelegate {
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
}
Thanks,but how can I make the popover disappear after I click it again. When I click it ,it appears again and the screen becomes darker and darker
I think it can be solved if there is your demo
Thanks Demo! I think your wanted behavior if modified as follows
before
func rightButtonDidTouch(sender: UIButton) {
let menu = TablePopover(tableFrame: CGRectMake(0, 0,100, 200))
menu.show(sender, inView: self.view)
}
after
func rightButtonDidTouch(sender: UIButton) {
let menu = TablePopover(tableFrame: CGRectMake(0, 0,100, 200))
menu.show(sender, inView: UIApplication.sharedApplication().keyWindow!)
}
many thanks! it worked perfectly
:+1:
The solution is not working for me. I tried exactly the solution. But for me, the table view's data source method cellForRowAtIndexPath is not being called. I have setup a demo repo for you to check out.
Hi! @Joker666 Thanks Demo! You should hold the PickerView in ViewController I think your wanted behavior if modified as follows
class ViewController: UIViewController {
var pickerView: PickerView?
@IBAction func buttonTapped(sender: UIButton) {
self.pickerView = PickerView(tableFrame: CGRectMake(0, 0, 200, 180))
self.pickerView?.show(sender, inView: UIApplication.sharedApplication().keyWindow!)
}
Thanks :)
it is conflict when I implement the delegate method and datasource method.