質問編集履歴
4
関数の引数について
title
CHANGED
File without changes
|
body
CHANGED
@@ -114,4 +114,51 @@
|
|
114
114
|
self.label.text = textField.text!の部分でlabelの部分でエラーが起きていてどう書いてもエラーが取れなくて困っています。
|
115
115
|
試しにcellForRowAt外にlabelのインスタンスを作ると外のインスタンスに対してはエラーが起きませんでした。
|
116
116
|
**エラーメッセージ**
|
117
|
-
Value of type 'ViewController' has no member 'label'
|
117
|
+
Value of type 'ViewController' has no member 'label'
|
118
|
+
|
119
|
+
```swift
|
120
|
+
//アラート
|
121
|
+
func alert(n: String){
|
122
|
+
|
123
|
+
|
124
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
125
|
+
|
126
|
+
// OKボタンの設定
|
127
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
128
|
+
(action:UIAlertAction!) -> Void in
|
129
|
+
|
130
|
+
// OKを押した時入力されていたテキストを表示
|
131
|
+
if let textFields = alert.textFields {
|
132
|
+
|
133
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
134
|
+
for textField in textFields {
|
135
|
+
|
136
|
+
self.item.insert(textField.text!, at: 0)
|
137
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
138
|
+
label.text = textField.text!
|
139
|
+
print(textField.text!)
|
140
|
+
}
|
141
|
+
}
|
142
|
+
})
|
143
|
+
alert.addAction(okAction)
|
144
|
+
|
145
|
+
// キャンセルボタンの設定
|
146
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
147
|
+
alert.addAction(cancelAction)
|
148
|
+
|
149
|
+
// テキストフィールドを追加
|
150
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
151
|
+
textField.placeholder = "テキスト"
|
152
|
+
})
|
153
|
+
|
154
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
155
|
+
|
156
|
+
// アラートを画面に表示
|
157
|
+
self.present(alert, animated: true, completion: nil)
|
158
|
+
}
|
159
|
+
|
160
|
+
alert(n: "kei")
|
161
|
+
print(alert)
|
162
|
+
```
|
163
|
+
|
164
|
+
関数の引数について
|
3
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,48 +5,13 @@
|
|
5
5
|
|
6
6
|
@IBOutlet weak var mytableView: UITableView!
|
7
7
|
var item = [String]()
|
8
|
+
|
9
|
+
@IBAction func addlabel(_ sender: Any) {
|
10
|
+
|
8
|
-
|
11
|
+
alert()
|
9
|
-
// テキストフィールド付きアラート表示
|
10
12
|
|
11
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
12
|
-
|
13
|
-
// OKボタンの設定
|
14
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
15
|
-
(action:UIAlertAction!) -> Void in
|
16
|
-
|
17
|
-
// OKを押した時入力されていたテキストを表示
|
18
|
-
if let textFields = alert.textFields {
|
19
|
-
|
20
|
-
// アラートに含まれるすべてのテキストフィールドを調べる
|
21
|
-
for textField in textFields {
|
22
|
-
//self.label()
|
23
|
-
self.item.insert(textField.text!, at: 0)
|
24
|
-
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
25
|
-
print(textField.text!)
|
26
|
-
self.Gesture()
|
27
|
-
self.doubleclic()
|
28
|
-
}
|
29
|
-
}
|
30
|
-
})
|
31
|
-
alert.addAction(okAction)
|
32
|
-
|
33
|
-
// キャンセルボタンの設定
|
34
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
35
|
-
alert.addAction(cancelAction)
|
36
|
-
|
37
|
-
// テキストフィールドを追加
|
38
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
39
|
-
textField.placeholder = "テキスト"
|
40
|
-
})
|
41
|
-
|
42
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
43
|
-
|
44
|
-
// アラートを画面に表示
|
45
|
-
self.present(alert, animated: true, completion: nil)
|
46
|
-
|
47
13
|
}
|
48
14
|
|
49
|
-
|
50
15
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
51
16
|
return item.count
|
52
17
|
}
|
2
エラーメッセージ
title
CHANGED
File without changes
|
body
CHANGED
@@ -147,4 +147,6 @@
|
|
147
147
|
|
148
148
|
**起きている問題**
|
149
149
|
self.label.text = textField.text!の部分でlabelの部分でエラーが起きていてどう書いてもエラーが取れなくて困っています。
|
150
|
-
試しにcellForRowAt外にlabelのインスタンスを作ると外のインスタンスに対してはエラーが起きませんでした。
|
150
|
+
試しにcellForRowAt外にlabelのインスタンスを作ると外のインスタンスに対してはエラーが起きませんでした。
|
151
|
+
**エラーメッセージ**
|
152
|
+
Value of type 'ViewController' has no member 'label'
|
1
こーどの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,12 +1,4 @@
|
|
1
1
|
```swift
|
2
|
-
//
|
3
|
-
// ViewController.swift
|
4
|
-
// btr-label
|
5
|
-
//
|
6
|
-
// Created by 西川継延 on 2018/02/25.
|
7
|
-
// Copyright © 2018年 西川継延. All rights reserved.
|
8
|
-
//
|
9
|
-
|
10
2
|
import UIKit
|
11
3
|
|
12
4
|
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{
|