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

質問編集履歴

3

ソースコード改変

2016/07/04 06:53

投稿

TsksHsgw
TsksHsgw

スコア23

title CHANGED
File without changes
body CHANGED
@@ -42,7 +42,7 @@
42
42
  return cell
43
43
  }
44
44
 
45
- @IBAction func buttonTapped(var sender: AnyObject) {
45
+ @IBAction func buttonTapped(sender: AnyObject) {
46
46
  let alertController = UIAlertController(title: "新しくリストを追加", message: "項目を入力して下さい。", preferredStyle: .Alert)
47
47
 
48
48
  let cancelAction = UIAlertAction(title: "Cancel", style: .Default){

2

ソースの改変

2016/07/04 06:52

投稿

TsksHsgw
TsksHsgw

スコア23

title CHANGED
File without changes
body CHANGED
@@ -59,7 +59,7 @@
59
59
  //textFieldの追加
60
60
  alertController.addTextFieldWithConfigurationHandler({(text: UITextField!) -> Void in
61
61
  text.tag = 0
62
- text.placeholder = "目標追加"
62
+ text.placeholder = "リスト名記入"
63
63
  })
64
64
 
65
65
 

1

修正前のソースコードを記入してしまったので、変更

2016/07/04 06:49

投稿

TsksHsgw
TsksHsgw

スコア23

title CHANGED
File without changes
body CHANGED
@@ -10,33 +10,72 @@
10
10
 
11
11
  ###ソースコード
12
12
  ```
13
- let alert:UIAlertController = UIAlertController(title:"新しくリストを追加",
14
- message: "項目を入力してください。",
15
- preferredStyle: UIAlertControllerStyle.Alert)
13
+ import UIKit
16
14
 
15
+ class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
16
+
17
+ var goalArray: [String] = []
18
+ @IBOutlet weak var goalTable: UITableView!
19
+ var toolBar: UIToolbar!
20
+
21
+ override func viewDidLoad() {
22
+ super.viewDidLoad()
23
+
24
+ toolBar = UIToolbar()
25
+ toolBar.sizeToFit()
26
+ let toolBarButton = UIBarButtonItem(title: "Done", style: .Plain, target: self, action: "doneButton")
27
+ toolBar.items = [toolBarButton]
28
+
29
+ }
30
+ override func didReceiveMemoryWarning() {
31
+ super.didReceiveMemoryWarning()
32
+ }
33
+
34
+ func tableView(tableView: UITableView, numberOfRowsInSection section: Int)->Int {
35
+ return goalArray.count
36
+ }
37
+
38
+ func tableView(tableView: UITableView, cellForAtIndexPath indexpath: NSIndexPath)->UITableViewCell {
39
+ let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
40
+
41
+ cell.textLabel?.text = goalArray[indexpath.row]
42
+ return cell
43
+ }
44
+
45
+ @IBAction func buttonTapped(var sender: AnyObject) {
46
+ let alertController = UIAlertController(title: "新しくリストを追加", message: "項目を入力して下さい。", preferredStyle: .Alert)
47
+
17
- let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel",
48
+ let cancelAction = UIAlertAction(title: "Cancel", style: .Default){
18
- style: UIAlertActionStyle.Cancel,
19
- handler:{
20
- (action:UIAlertAction!) -> Void in
21
- print("Cancel")
49
+ action in NSLog("Cancel")
50
+ }
51
+
52
+ let otherAction = UIAlertAction(title: "Done", style: .Default){
53
+ action in NSLog("Done")
54
+ }
55
+
56
+ alertController.addAction(cancelAction)
57
+ alertController.addAction(otherAction)
58
+
59
+ //textFieldの追加
60
+ alertController.addTextFieldWithConfigurationHandler({(text: UITextField!) -> Void in
61
+ text.tag = 0
62
+ text.placeholder = "目標を追加"
22
63
  })
64
+
65
+
23
- let defaultAction:UIAlertAction = UIAlertAction(title: "OK",
66
+ alertController.addTextFieldWithConfigurationHandler({(text: UITextField!) -> Void in
67
+
68
+ text.tag = 1
24
- style: UIAlertActionStyle.Default,
69
+ text.placeholder = "期限を設定(必須)"
25
- handler:{
26
- (action:UIAlertAction!) -> Void in
27
- print("OK")
28
70
  })
29
- alert.addAction(cancelAction)
30
- alert.addAction(defaultAction)
31
71
 
32
- //textfiledの追加
72
+
33
- alert.addTextFieldWithConfigurationHandler({(text:UITextField!) -> Void in
73
+
34
- textField.placeHolder = "リスト名を入力"
35
- })
36
- alert.addTextFieldWithConfigurationHandler({(text:UITextField!) -> Void in
37
- textField.placeHolder = "期限を入力"
38
- })
39
- presentViewController(alert, animated: true, completion: nil)
74
+ presentViewController(alertController, animated: true, completion: nil)
75
+ }
76
+
77
+ }
78
+
40
79
  ```
41
80
 
42
81
  これまでに、defaultAction内に、textDidEndEditingメソッドを追加してみたりなどしてみたのですが、