He *_*何一非 2 didselectrowatindexpath ipad uipopovercontroller ios swift
我想popoverPresentationController在用户点击iPad中的单元格时显示.这是我的代码:
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
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这在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
}
}
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*chi 10
您正在从整个tableView的框架中显示弹出窗口,因此我认为它不在屏幕之外.尝试从单元格的框架中显示它.
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 {
popView.sourceView = tableView
popView.sourceRect = tableView.cellForRowAtIndexPath(indexPath)!.frame
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3771 次 |
| 最近记录: |