我有两个控制器.第一个有一个带有书签按钮项目的导航栏,我按下它来显示我的第二个控制器,里面有一个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) } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。