回答編集履歴

5

修正

2016/12/11 01:36

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,4 +1,4 @@
1
- とりあえず思いついた2種類の方法を載せますのでしてみてください。
1
+ とりあえず思いついた2種類の方法を載せますので参考にしてみてください。
2
2
 
3
3
 
4
4
 

4

修正

2016/12/11 01:36

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,6 +1,4 @@
1
- `IndexPath`が取れればよいのであれば`Cell`側にプロパティで持たせるのが簡単だと思います。
2
-
3
- ボタンが押され時に自分`indexPath.row`見れば何番かは分かります。
1
+ とりあえず思いつい2種類方法載せますので試してみてください
4
2
 
5
3
 
6
4
 

3

修正

2016/12/11 01:35

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- ★ セルに`indexPath`のプロパティを作成する
7
+ ★ セルに`IndexPath`のプロパティを作成する
8
8
 
9
9
 
10
10
 
@@ -44,7 +44,7 @@
44
44
 
45
45
 
46
46
 
47
- ★ ボタンの`tag`に`indexPath.row`を設定する
47
+ セルボタンの`tag`に`indexPath.row`を設定する
48
48
 
49
49
 
50
50
 

2

修正

2016/12/11 01:30

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,6 +1,10 @@
1
1
  `IndexPath`が取れればよいのであれば`Cell`側にプロパティで持たせるのが簡単だと思います。
2
2
 
3
3
  ボタンが押された時に自分の`indexPath.row`を見れば何番かは分かります。
4
+
5
+
6
+
7
+ ★ セルに`indexPath`のプロパティを作成する
4
8
 
5
9
 
6
10
 
@@ -37,3 +41,45 @@
37
41
  }
38
42
 
39
43
  ```
44
+
45
+
46
+
47
+ ★ ボタンの`tag`に`indexPath.row`を設定する
48
+
49
+
50
+
51
+ ```swift
52
+
53
+ // セル作成
54
+
55
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
56
+
57
+ let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath as IndexPath) as! CustomCell
58
+
59
+ cell.button.tag = indexPath.row
60
+
61
+ return cell
62
+
63
+ }
64
+
65
+
66
+
67
+ // カスタムセルクラス
68
+
69
+ class CustomCell: UITableViewCell {
70
+
71
+
72
+
73
+ @IBOutlet weak var button: UIButton!
74
+
75
+
76
+
77
+ @IBAction func pushCellButton(_ sender: UIButton) {
78
+
79
+ print(sender.tag)
80
+
81
+ }
82
+
83
+ }
84
+
85
+ ```

1

修正

2016/12/11 01:16

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,6 +1,6 @@
1
1
  `IndexPath`が取れればよいのであれば`Cell`側にプロパティで持たせるのが簡単だと思います。
2
2
 
3
- ボタンが押された時自分の`indexPath.row`を見れば何番かは分かります。
3
+ ボタンが押された時自分の`indexPath.row`を見れば何番かは分かります。
4
4
 
5
5
 
6
6