当敲击细胞时,popover不会显示出来

时间:2015-02-24 15:18:31

标签: ios uitableview swift

我想使用uitableviewrowaction来显示popoverview,用户可以在其中选择颜色。当我选择导航项作为发件人时,弹出窗口很有用。一旦我将发送者更改为tableViewCell,背景就会变暗,但是popover不会显示。这是我的代码

从导航项

提供的popover

enter image description here

uitableviewrowaction

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath 
indexPath: NSIndexPath) -> [AnyObject]?
{
    var colorRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Color", handler:
        { (action:UITableViewRowAction!, path: NSIndexPath!) -> Void in

            self.performSegueWithIdentifier("popoverSegue", sender:self.mainTableViewOutlet.cellForRowAtIndexPath(path))
    })

    return [colorRowAction, deleteRowAction]
}

准备segue

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)       
{
    if segue.identifier == "popoverSegue" {
        colorPopover = segue.destinationViewController as SBColorPopover
        colorPopover.modalPresentationStyle =      
UIModalPresentationStyle.Popover
        colorPopover.popoverPresentationController!.delegate = self
        colorPopover.delegate = self
}

1 个答案:

答案 0 :(得分:0)

解决方案:

因为我以编程方式调用performSegue,所以我必须定义popoverViewController的sourceRect:

colorPopover = segue.destinationViewController as SBColorPopover
        colorPopover.modalPresentationStyle =     
UIModalPresentationStyle.Popover
        colorPopover.popoverPresentationController!.delegate = self
//define sourceRect
        colorPopover.popoverPresentationController?.sourceRect =
sender!.frame
        colorPopover.delegate = self