Swift:选择tableview单元格时关闭PopOver
发布时间:2020-12-14 04:57:37 所属栏目:百科 来源:网络整理
导读:我有两个控制器.第一个有一个带有书签按钮项目的导航栏,我按下它来显示我的第二个控制器,里面有一个tableview. Example project from this link : http://www.koraybirand.co.uk/download/xcode/PopTest.zip 我希望能够选择一个单元格然后关闭弹出视图. 另一
我有两个控制器.第一个有一个带有书签按钮项目的导航栏,我按下它来显示我的第二个控制器,里面有一个tableview.
Example project from this link : http://www.koraybirand.co.uk/download/xcode/PopTest.zip 我希望能够选择一个单元格然后关闭弹出视图. 另一个奇怪的行为是,第一个单元格显示一个警报视图控制器,它可以在iPhone上正常工作,但在iPad上,弹出窗口会突然调整到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) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |