【发布时间】:2015-10-22 21:25:23
【问题描述】:
当用户单击 iPad 中的单元格时,我想显示 popoverPresentationController。这是我的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.section == 0){
if(indexPath.row == 0){
let textToShare = NSLocalizedString("SHARE_MESSAGE", comment: "Message...")
if let appStoreURL = NSURL(string: "http://www.google.com/") {
let objectsToShare = [textToShare, appStoreURL]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
if let popView = activityVC.popoverPresentationController {
let v = tableView as UIView
popView.sourceView = v
popView.sourceRect = v.bounds
}
}
}
}
}
在 iPad 上是错误的(屏幕上没有显示)。那我该如何解决呢?
PS:这是 UIButton 的代码,它在 iPad 上运行良好(显示在屏幕上):
@IBAction func shareButtonAction(sender: AnyObject) {
let textToShare = NSLocalizedString("SHARE_MESSAGE", comment: "Message...")
if let appStoreURL = NSURL(string: "http://www.google.com/") {
let objectsToShare = [textToShare, appStoreURL]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
if let popView = activityVC.popoverPresentationController {
let v = sender as! UIView
popView.sourceView = v
popView.sourceRect = v.bounds
}
}
}
【问题讨论】:
标签: ios swift ipad uipopovercontroller didselectrowatindexpath