回答編集履歴

3

修正

2016/05/01 07:27

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,4 +1,4 @@
1
- objective-C
1
+ Objective-C
2
2
 
3
3
  ---
4
4
 
@@ -7,6 +7,70 @@
7
7
 
8
8
 
9
9
  [iOS8でのダイアログ表示:廃止になるUIAlertViewと推奨されているUIAlertControllerのメリット](http://qiita.com/Night___/items/f2877236a4182c566eed)
10
+
11
+
12
+
13
+ ★ リンクを参考にしたサンプル
14
+
15
+ ```objc
16
+
17
+
18
+
19
+ // ボタン押下時にAlertを表示する
20
+
21
+ - (IBAction)pushButton:(UIButton *)sender {
22
+
23
+
24
+
25
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"タイトル" message:@"メッセージ" preferredStyle:UIAlertControllerStyleAlert];
26
+
27
+
28
+
29
+ [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
30
+
31
+ // 「はい」ボタンが押された時の処理
32
+
33
+ [self otherButtonPushed];
34
+
35
+ }]];
36
+
37
+ [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
38
+
39
+ // 「いいえ」ボタンが押された時の処理
40
+
41
+ [self cancelButtonPushed];
42
+
43
+ }]];
44
+
45
+
46
+
47
+ // 画面に表示します
48
+
49
+ [self presentViewController:alertController animated:YES completion:nil];
50
+
51
+ }
52
+
53
+
54
+
55
+ // アラートのはいボタン押下処理
56
+
57
+ - (void)otherButtonPushed {
58
+
59
+ NSLog(@"はい!");
60
+
61
+ }
62
+
63
+
64
+
65
+ // アラートのいいえボタン押下処理
66
+
67
+ - (void)cancelButtonPushed {
68
+
69
+ NSLog(@"いいえ!");
70
+
71
+ }
72
+
73
+ ```
10
74
 
11
75
 
12
76
 

2

修正

2016/05/01 07:27

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,12 +1,28 @@
1
+ objective-C
2
+
3
+ ---
4
+
1
5
  参考にするサイトとして、以下はいかがでしょうか?
2
6
 
3
- サンプルも載っていて分かりやすいと思います。
4
7
 
8
+
5
- Swift2ないですがprintln だけ printに置き換えると大丈夫だと思います。
9
+ [iOS8のダイアログ表示:廃止にるUIAlertViewと推奨されてるUIAlertControllerのメリット](http://qiita.com/Night___/items/f2877236a4182c566eed)
10
+
11
+
12
+
13
+
14
+
15
+ Swift
16
+
17
+ ---
6
18
 
7
19
 
8
20
 
9
21
  [Swift:UIAlertController でアラートを表示するサンプルコード](http://www.sirochro.com/note/swift-uialertcontroller-sample/)
22
+
23
+
24
+
25
+ ※Swift2ではないですがprintln だけ printに置き換えると大丈夫だと思います
10
26
 
11
27
 
12
28
 

1

修正

2016/05/01 07:19

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -7,3 +7,71 @@
7
7
 
8
8
 
9
9
  [Swift:UIAlertController でアラートを表示するサンプルコード](http://www.sirochro.com/note/swift-uialertcontroller-sample/)
10
+
11
+
12
+
13
+ ★ 簡単なサンプル
14
+
15
+ ```swift
16
+
17
+
18
+
19
+ // ボタン押下時にアラートを表示します
20
+
21
+ @IBAction func pushButton(sender: AnyObject) {
22
+
23
+
24
+
25
+ let alert = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
26
+
27
+
28
+
29
+ let action1 = UIAlertAction(title: "Action1", style: .Default, handler: { action in
30
+
31
+ print("Action1")
32
+
33
+ })
34
+
35
+
36
+
37
+ let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: { action in
38
+
39
+ print("Cancel")
40
+
41
+ })
42
+
43
+
44
+
45
+ alert.addAction(action1)
46
+
47
+ alert.addAction(cancel)
48
+
49
+
50
+
51
+ presentViewController(alert, animated: true, completion: nil)
52
+
53
+ }
54
+
55
+ ```
56
+
57
+
58
+
59
+ ★ もっともシンプルなアラート
60
+
61
+ ```swift
62
+
63
+ // ユーザーにお知らせするだけのアラート
64
+
65
+ @IBAction func pushButton(sender: AnyObject) {
66
+
67
+
68
+
69
+ let alert = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
70
+
71
+ alert.addAction( UIAlertAction(title: "OK", style: .Default, handler: nil))
72
+
73
+ presentViewController(alert, animated: true, completion: nil)
74
+
75
+ }
76
+
77
+ ```