teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正

2016/07/05 16:05

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -5,16 +5,17 @@
5
5
  ```swift
6
6
  import UIKit
7
7
  class ViewController: UIViewController {
8
+ let sub = Sub()
8
9
 
9
10
  override func viewDidLoad() {
10
11
  super.viewDidLoad()
11
12
 
12
- Sub().alert(self)
13
+ sub.alert(self)
13
14
  }
14
15
  }
15
16
 
16
- class Sub: UIViewController {
17
+ class Sub: UIViewController {
17
-
18
+
18
19
  func alert(viewController: UIViewController) {
19
20
  let alert = UIAlertController(title: "abc", message: "", preferredStyle: .Alert)
20
21
  alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action) in print("Cancel!") }))

1

修正

2016/07/05 16:05

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,3 +1,5 @@
1
+ `presentViewController`はアラートを表示する`ViewController`のオブジェクトが必要なので、引数で渡しています。
2
+
1
3
  とりあえず以下の様にすることで呼び出すことはできます。
2
4
 
3
5
  ```swift