Example project from this link : http://www.koraybirand.co.uk/download/xcode/PopTest.zip
我希望能够选择一个单元格然后关闭d出视图.
另一个奇怪的行为是,第一个单元格显示一个警报视图控制器,它可以在iPhone上正常工作,但在iPad上,d出窗口会突然调整到alervIEwcontroller的大小.
这是我的主视图控制器:
class VIEwController: UIVIEwController,UIPopoverPresentationControllerDelegate {overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib.}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated.}overrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) { if segue.IDentifIEr == "popoverSegue" { let popoverVIEwController = segue.destinationVIEwController as! UIVIEwController popoverVIEwController.modalPresentationStyle = UIModalPresentationStyle.Popover popoverVIEwController.popoverPresentationController!.delegate = self }}func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return UIModalPresentationStyle.None}}
这是我的popover:
class menuVIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDataSource {var links : [String] = ["Share","Manage"]var currentPopover:UIPopoverController!@IBOutlet weak var tableVIEw: UItableVIEw!func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int { return links.count}func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int { return 1}func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.item == 0 { let alertController = UIAlertController(Title: "Share",message: "No Bookmarks to Share",preferredStyle: .Alert) let cancelAction = UIAlertAction(Title: "dismiss",style: .Cancel) { (_) in } alertController.addAction(cancelAction) self.presentVIEwController(alertController,animated: true) {} }}func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell { let cell = tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath) as! UItableVIEwCell cell.textLabel?.text = links[indexPath.row] as String return cell}overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad()}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}}
谢谢.
解决方法 self.dismissVIEwControllerAnimated(true,completion:nil)在menuVIEwController中足以解除popover.所以代码看起来像这样:
func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.item == 0 { let alertController = UIAlertController(Title: "Share",animated: true) {} self.dismissVIEwControllerAnimated(true,completion: nil) }}总结
以上是内存溢出为你收集整理的Swift:选择tableview单元格时关闭PopOver全部内容,希望文章能够帮你解决Swift:选择tableview单元格时关闭PopOver所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)