22
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iPadでUIAlertControllerのActionSheetが落ちる問題

Posted at

UIAlertControllerのActionSheetをiPadで普通にやったら落ちる。
sourceViewとsourceRectを指定しなければいけない。

MyViewController.swift
class ViewController: UIViewController {
    @IBAction func pushButton(sender: UIButton) {
        let ac = UIAlertController(title: "hoge", message: "moge", preferredStyle: .ActionSheet)
        let ok = UIAlertAction(title: "ok", style: .Default, handler: nil)
        ac.addAction(ok)
        
        ac.popoverPresentationController?.sourceView = view
        ac.popoverPresentationController?.sourceRect = sender.frame
        presentViewController(ac, animated: true, completion: nil)
    }
}

sourceViewは表示するviewを指定して、
sourceRectはそのviewの中のどこからピヨっと表示するかを指定する。

iOS Simulator Screen Shot 2015.04.08 19.45.15.png

iPhoneではsourceViewとsourceRectは関係ない。
iOS Simulator Screen Shot 2015.04.08 19.46.50.png

22
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?