回答編集履歴

2

書き換え

2015/05/28 12:17

投稿

7hikolin
7hikolin

スコア124

test CHANGED
@@ -8,56 +8,62 @@
8
8
 
9
9
 
10
10
 
11
- func singleAlert(title:String, message:String, buttonTitle:String){
11
+ func singleAlert(title:String, message:String, buttonTitle:String){
12
12
 
13
- if objc_getClass("UIAlertController") != nil {
13
+
14
14
 
15
- let myAlert = UIAlertController(
15
+ //iOS8以上
16
16
 
17
- title: title,
17
+ if objc_getClass("UIAlertController") != nil {
18
18
 
19
- message: message,
19
+ let myAlert = UIAlertController(
20
20
 
21
+ title: title,
22
+
23
+ message: message,
24
+
21
- preferredStyle: .Alert)
25
+ preferredStyle: .Alert)
22
26
 
23
27
 
24
28
 
25
- // OKのアクションを作成する.
29
+ // OKのアクションを作成する.
26
30
 
27
- let OkAction = UIAlertAction(title: buttonTitle, style: .Default) { action in
31
+ let OkAction = UIAlertAction(title: buttonTitle, style: .Default) { action in
28
32
 
29
33
 
30
34
 
31
- }
35
+ }
32
36
 
33
37
 
34
38
 
35
- // Actionを追加する.
39
+ // Actionを追加する.
36
40
 
37
- myAlert.addAction(OkAction)
41
+ myAlert.addAction(OkAction)
38
42
 
39
43
 
40
44
 
41
- // UIAlertを発動する.
45
+ // UIAlertを発動する.
42
46
 
43
- self.window?.rootViewController?.presentViewController(myAlert, animated: true, completion: nil)
47
+ presentViewController(myAlert, animated: true, completion: nil)
44
48
 
45
49
 
46
50
 
47
- } else {
51
+ } else {
48
52
 
49
- var alert = UIAlertView()
53
+ //iOS7以下
50
54
 
51
- alert.title = title
55
+ var alert = UIAlertView()
52
56
 
53
- alert.message = message
57
+ alert.title = title
54
58
 
55
- alert.addButtonWithTitle(buttonTitle)
59
+ alert.message = message
56
60
 
57
- alert.show()
61
+ alert.addButtonWithTitle(buttonTitle)
58
62
 
59
- }
63
+ alert.show()
60
64
 
61
- }
65
+ }
66
+
67
+ }
62
68
 
63
69
  ```

1

変更

2015/05/28 12:17

投稿

7hikolin
7hikolin

スコア124

test CHANGED
@@ -1,6 +1,6 @@
1
1
  ios7ではUIAlertViewを使います。
2
2
 
3
- 以下のこーどを貼けて、呼び出して使ってください。
3
+ 以下のようにiOS7と8で切けて使ってください。
4
4
 
5
5
 
6
6