corin8823 / Popover

Popover is a balloon library like Facebook app. It is written in pure swift.
MIT License
2.11k stars 327 forks source link

how to popover a tableView in a tableViewController #14

Closed ghost closed 8 years ago

ghost commented 8 years ago

it is conflict when I implement the delegate method and datasource method.

corin8823 commented 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) {

  }
}
ghost commented 8 years ago

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

corin8823 commented 8 years ago

I think it can be solved if there is your demo

ghost commented 8 years ago

https://github.com/marshallYin/Weibo---Swift

corin8823 commented 8 years ago

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!)
}
ghost commented 8 years ago

many thanks! it worked perfectly

corin8823 commented 8 years ago

:+1:

Joker666 commented 8 years ago

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.

https://github.com/Joker666/TestTablePop

corin8823 commented 8 years ago

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!)
    }
Joker666 commented 8 years ago

Thanks :)