質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
```swift
|
2
|
-
struct Cell {
|
3
|
-
var detail: [String]
|
4
|
-
var lightswipe: Bool//detail
|
5
|
-
var tag: Int
|
6
|
-
}
|
7
|
-
|
8
2
|
import UIKit
|
9
3
|
|
10
4
|
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{
|
@@ -16,6 +10,11 @@
|
|
16
10
|
var products: [Cell] = []//detail
|
17
11
|
|
18
12
|
|
13
|
+
class namelabel {
|
14
|
+
var labels: [UILabel] = []
|
15
|
+
}
|
16
|
+
|
17
|
+
|
19
18
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
20
19
|
// 全データの合計
|
21
20
|
return titles.count + products.count
|
@@ -26,9 +25,15 @@
|
|
26
25
|
let index = Int(floor(Double(indexPath.row / 2)))
|
27
26
|
//セルタップ時のハイライトについて
|
28
27
|
cell.selectionStyle = .none
|
28
|
+
|
29
29
|
// title行
|
30
30
|
if indexPath.row % 2 == 0 {
|
31
31
|
|
32
|
+
//ここ再確認
|
33
|
+
//破線について
|
34
|
+
let path = UIBezierPath()
|
35
|
+
path.setLineDash([6.0, 2.0], count: 2, phase: 0.0)
|
36
|
+
|
32
37
|
guard titles.count > 0 else {
|
33
38
|
return cell
|
34
39
|
}
|
@@ -48,9 +53,7 @@
|
|
48
53
|
guard item.detail.count > 0 else {
|
49
54
|
return cell
|
50
55
|
}
|
51
|
-
|
52
|
-
|
56
|
+
let hoge = namelabel()
|
53
|
-
|
54
57
|
//labelについて
|
55
58
|
for i in item.detail {
|
56
59
|
let label = UILabel()
|
@@ -65,11 +68,11 @@
|
|
65
68
|
label.layer.cornerRadius = 5
|
66
69
|
label.layer.masksToBounds = true
|
67
70
|
cell.contentView.addSubview(label)
|
68
|
-
labels.append(label)
|
71
|
+
hoge.labels.append(label)
|
69
72
|
}
|
70
73
|
|
71
74
|
var preLabel: UILabel? = nil
|
72
|
-
for l in labels {
|
75
|
+
for l in hoge.labels {
|
73
76
|
|
74
77
|
l.translatesAutoresizingMaskIntoConstraints = false
|
75
78
|
if (preLabel == nil) {
|
@@ -89,13 +92,14 @@
|
|
89
92
|
**困っている箇所**
|
90
93
|
```swift
|
91
94
|
func deletealert() {
|
95
|
+
let hoge = namelabel()
|
92
96
|
let alert = UIAlertController(title:"you realy want to delete?", message: "メッセージ", preferredStyle: .alert)
|
93
97
|
|
94
98
|
let okAction = UIAlertAction(title: "YES", style: .default, handler: {
|
95
99
|
(action:UIAlertAction!) -> Void in
|
96
100
|
|
97
101
|
//labelの削除について
|
98
|
-
|
102
|
+
hoge.labels.tag = 1
|
99
103
|
|
100
104
|
self.view.subviews.forEach {
|
101
105
|
if $0.tag == 1{
|
@@ -118,7 +122,7 @@
|
|
118
122
|
|
119
123
|
//長押しやダブルクリックについて
|
120
124
|
@objc func longpress(sender: UILongPressGestureRecognizer){
|
121
|
-
|
125
|
+
let hoge = namelabel()
|
122
126
|
// 長押し開始〜
|
123
127
|
if(sender.state == UIGestureRecognizerState.began)
|
124
128
|
{
|
@@ -126,8 +130,7 @@
|
|
126
130
|
} else if (sender.state == UIGestureRecognizerState.ended)
|
127
131
|
{
|
128
132
|
//labelの削除について
|
129
|
-
products[0].detail[0] = ""
|
130
|
-
|
133
|
+
hoge.labels.tag = 1
|
131
134
|
|
132
135
|
self.view.subviews.forEach {
|
133
136
|
if $0.tag == 1{
|
@@ -141,37 +144,40 @@
|
|
141
144
|
|
142
145
|
}
|
143
146
|
|
147
|
+
@objc func doubletap(sender: UITapGestureRecognizer){
|
148
|
+
if(sender.state == UIGestureRecognizerState.began)
|
149
|
+
{
|
150
|
+
}else if(sender.state == UIGestureRecognizerState.ended)
|
151
|
+
{
|
152
|
+
deletealert()
|
153
|
+
print("tapされたよ")
|
154
|
+
}
|
155
|
+
|
156
|
+
}
|
157
|
+
|
144
158
|
func Gesture() {
|
145
159
|
|
160
|
+
let hoge = namelabel()
|
146
161
|
// UILongPressGestureRecognizerインスタンス作成
|
147
162
|
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(ViewController.longpress(sender:)))
|
148
163
|
|
149
164
|
// 時間(デフォルト0.5秒)
|
150
165
|
longPressGesture.minimumPressDuration = 0.5
|
151
|
-
|
166
|
+
hoge.labels[0].isUserInteractionEnabled = true
|
152
|
-
|
167
|
+
hoge.labels[0].addGestureRecognizer(longPressGesture)
|
153
168
|
|
154
169
|
|
155
170
|
|
156
171
|
}
|
157
172
|
|
158
173
|
func doubleclic(){
|
174
|
+
let hoge = namelabel()
|
159
175
|
// ダブルタップ
|
160
176
|
let doubeltapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.doubletap(sender:)))
|
161
177
|
doubeltapGesture.numberOfTapsRequired = 2
|
162
|
-
|
178
|
+
hoge.labels[0].isUserInteractionEnabled = true
|
163
|
-
|
179
|
+
hoge.labels[0].addGestureRecognizer(doubeltapGesture)
|
164
180
|
}
|
165
|
-
|
166
|
-
@objc func doubletap(sender: UITapGestureRecognizer){
|
167
|
-
if(sender.state == UIGestureRecognizerState.began)
|
168
|
-
{
|
169
|
-
}else if(sender.state == UIGestureRecognizerState.ended)
|
170
|
-
{
|
171
|
-
deletealert()
|
172
|
-
}
|
173
|
-
|
174
|
-
}
|
175
181
|
```
|
176
182
|
### 実現したい事・困っている事
|
177
183
|
products.isUserInteractionEnabled = true
|
@@ -180,4 +186,11 @@
|
|
180
186
|
Value of type '[Cell]' has no member 'isUserInteractionEnabled'
|
181
187
|
Value of type '[Cell]' has no member 'addGestureRecognizer'
|
182
188
|
上記のコードでこの様なエラーが出てしまいました。実現したい事としてはセルの中のラベルをダブルタップや長押しをできる様にしたいです。
|
183
|
-
しかし、コーディングの際にcellForRowAT内にラベルのインスタンスを作ったのでどう結びつければいいのか分からなくて困っています。
|
189
|
+
しかし、コーディングの際にcellForRowAT内にラベルのインスタンスを作ったのでどう結びつければいいのか分からなくて困っています。
|
190
|
+
|
191
|
+
**現在困っている事**
|
192
|
+
classを作ることにより上記のエラーは取れましたがそれに伴い、以下の場所でエラーが出来ました。
|
193
|
+
エラーの意味は理解できるのですがその対処法が分からなくて困っています。
|
194
|
+
```
|
195
|
+
hoge.labels.tag = 1 //Value of type '[UILabel]' has no member 'tag'
|
196
|
+
```
|