回答編集履歴

2

Bool値が逆だった

2015/07/30 06:58

投稿

__moai
__moai

スコア264

test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- cell.detailTextLabel?.hidden = self.isShowDetailTextLabel
21
+ cell.detailTextLabel?.hidden = !self.isShowDetailTextLabel
22
22
 
23
23
 
24
24
 

1

実際の実装想定となるコードを追加

2015/07/30 06:58

投稿

__moai
__moai

スコア264

test CHANGED
@@ -1 +1,39 @@
1
1
  手っ取り早いのはセルを使ってるViewControllerクラス側でdetailTextLabelの表示フラグを持っておくことですかね、cellForRowAtIndexPath関数内で表示フラグを見てdetailTextLabelを表示するかどうかの処理を書いておいて、表示フラグが切り替わったタイミングでreloadDataを呼び出すとうまくいくのではないでしょうか
2
+
3
+
4
+
5
+ ```Swift
6
+
7
+ var tableView: UITableView!
8
+
9
+
10
+
11
+ var isShowDetailTextLabel = false // falseとしてますが初期値としたいBool値で
12
+
13
+
14
+
15
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
16
+
17
+ let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as! UITableViewCell
18
+
19
+
20
+
21
+ cell.detailTextLabel?.hidden = self.isShowDetailTextLabel
22
+
23
+
24
+
25
+ return cell
26
+
27
+ }
28
+
29
+
30
+
31
+ @IBAction func test(sender: AnyObject) {
32
+
33
+ self.isShowDetailTextLabel = !self.isShowDetailTextLabel
34
+
35
+ self.tableView.reloadData()
36
+
37
+ }
38
+
39
+ ```