2015-02-24 82 views
0

我想使用一個uitableviewrowaction來顯示popoverview,其中用戶可以選擇一種顏色。當我選擇一個導航項目作爲發件人時,popover效果很好。只要我將發件人更改爲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] 
} 

提出了賽格瑞

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 
} 
+0

檢查self.mainTableViewOutlet.cellForRowAtIndexPath(路徑)返回零,而我不是看你在prepareForSegue與發送者做任何事情 – Arbitur 2015-02-24 15:22:01

+0

你是對的,我不得不在調用segue方法時調用colorPopover.popoverViewController.sourceRect = sender.frame。現在它的工作。謝謝。 – Christian 2015-02-24 17:14:55

回答

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