我有一个UITableView
的定制单元格填充NSManagedObjects
。我在自定义单元格上配置了一个按钮,以便在选择时显示弹出窗口。从UIViewController传递数据到UIPopover
我最初尝试使用performSegueWithIdentifier
和prepareForSegue
来实现弹出窗口,但UIPopover segues似乎不喜欢来自UITableViews的动态内容。通过self.presentViewController
实例化弹出窗口对我来说很有用,但我很难搞清楚如何将数据传递给它。
func demoButtonAction(sender: AnyObject) {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("demoPopover")
vc?.modalPresentationStyle = .Popover
vc?.preferredContentSize = CGSizeMake(tableView.bounds.width * 0.75, tableView.bounds.height * 0.75)
if let presentationController = vc?.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = .Any
// sender is a UIButton on a custom cell
presentationController.sourceView = sender as? UIView
presentationController.sourceRect = CGRectMake(tableView.bounds.origin.x, tableView.bounds.origin.y, sender.bounds.width, sender.bounds.height/2)
self.presentViewController(vc!, animated: true, completion: nil)
}
}
下面是我打算如何获得想要传递给popover的ViewController的对象的方法。
let button = sender as! UIButton
let view = button.superview
let cell = view?.superview as! MyCustomTableViewCell
let indexPath: NSIndexPath = self.tableView.indexPathForCell(cell)!
let myObjectIWantToPass = fetchedResultsController.objectAtIndexPath(indexPath) as! MyNSManagedObject
我将如何得到我的对象从ViewController
到PopoverViewController
?我应该通过对象还是有另一条路线我应该去?