質問編集履歴

4

追記しました

2016/08/12 15:31

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
@@ -94,6 +94,44 @@
94
94
 
95
95
 
96
96
 
97
+ ```CustomCell
98
+
99
+ class CellForWeather: UITableViewCell {
100
+
101
+
102
+
103
+ @IBOutlet weak var weatherIconImage: UIImageView!
104
+
105
+ @IBOutlet weak var capitalLabel : UILabel!
106
+
107
+
108
+
109
+ override func awakeFromNib() {
110
+
111
+ super.awakeFromNib()
112
+
113
+
114
+
115
+ }
116
+
117
+
118
+
119
+ func setdata(capitalstr:String,iconimg:UIImage){
120
+
121
+ weatherIconImage.image = iconimg
122
+
123
+ capitalLabel.text = capitalstr
124
+
125
+ }
126
+
127
+ }
128
+
129
+
130
+
131
+ ```
132
+
133
+
134
+
97
135
  このコードの2行目で```Could not cast value of type 'UITableViewCell' (0x1a0fe4718) to 'weatherforecast_swift.CellForWeather' (0x100057828).```と出て落ちてしまいます。
98
136
 
99
137
 
@@ -102,8 +140,8 @@
102
140
 
103
141
 
104
142
 
105
- 私の考えでは、returnするタイプがCellForWeatherではないと思うのですが、するとDatasouceエラーが出てしまます。(多分間違ってるのでしょう
143
+ 追記2:if cell==nilの時の挙動を書かないといけないのだといますが、よう書けばいいでしょうか?
106
144
 
107
145
 
108
146
 
109
- ご教示お願いいたします
147
+ ご教示お願いします

3

エラー追記

2016/08/12 15:31

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,65 @@
45
45
 
46
46
 
47
47
  これと別のファイルで```cell = tableView.dequeueReusableCellWithIdentifier("cell_object") as? CustomTableViewCell```をして、Cellがnilの時のif文に```CustomTableViewCell.awakeFromNib()```と書きました。runすると、セルがnilだといって落ちてしまいます。どこを直せばいいでしょうか?ご教示おねがいします。
48
+
49
+
50
+
51
+ (追記)
52
+
53
+
54
+
55
+ ```swift
56
+
57
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
58
+
59
+
60
+
61
+ let cell_object = tableView.dequeueReusableCellWithIdentifier("cell_object", forIndexPath: indexPath) as! CellForWeather
62
+
63
+
64
+
65
+ if (indexPath.row % 2 == 0) {
66
+
67
+ cell_object.backgroundColor = UIColor(hue:0.0,saturation:0.0,brightness:0.67,alpha:1.0)
68
+
69
+ }
70
+
71
+ // 奇数セル
72
+
73
+ else {
74
+
75
+ cell_object.backgroundColor = UIColor(hue:0.0,saturation:0.0,brightness:0.73,alpha:1.0)
76
+
77
+ }
78
+
79
+
80
+
81
+ // セルの向きを横向きに
82
+
83
+ cell_object.contentView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI) / 2);
84
+
85
+
86
+
87
+ CellForWeather().setdata("Tokyo",iconimg: UIImage(named:"01d.png")!)
88
+
89
+ return cell_object
90
+
91
+ }
92
+
93
+ ```
94
+
95
+
96
+
97
+ このコードの2行目で```Could not cast value of type 'UITableViewCell' (0x1a0fe4718) to 'weatherforecast_swift.CellForWeather' (0x100057828).```と出て落ちてしまいます。
98
+
99
+
100
+
101
+ **cell.xib**での**Identifier**は**cell_objec**tで、**CustomClass**は**CellForWeather**と確認しました。
102
+
103
+
104
+
105
+ 私の考えでは、returnするタイプがCellForWeatherではないかと思うのですが、するとDatasouceの方にエラーが出てしまいます。(多分間違っているのでしょう)
106
+
107
+
108
+
109
+ ご教示お願いいたします。

2

題名変更

2016/08/12 04:37

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
@@ -1 +1 @@
1
- <至急>swiftでのxibファイルの呼び出しでcellがnilになる(落ちる)
1
+ 至急swiftでのxibファイルの呼び出しでcellがnilになる(落ちる)
test CHANGED
File without changes

1

題名の変更

2016/08/11 18:18

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
@@ -1 +1 @@
1
- xibファイルの呼び出し
1
+ <至急>swiftでのxibファイルの呼び出しでcellがnilになる(落ちる)
test CHANGED
File without changes