質問編集履歴
4
追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -46,10 +46,29 @@
|
|
46
46
|
}
|
47
47
|
```
|
48
48
|
|
49
|
+
```CustomCell
|
50
|
+
class CellForWeather: UITableViewCell {
|
51
|
+
|
52
|
+
@IBOutlet weak var weatherIconImage: UIImageView!
|
53
|
+
@IBOutlet weak var capitalLabel : UILabel!
|
54
|
+
|
55
|
+
override func awakeFromNib() {
|
56
|
+
super.awakeFromNib()
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
func setdata(capitalstr:String,iconimg:UIImage){
|
61
|
+
weatherIconImage.image = iconimg
|
62
|
+
capitalLabel.text = capitalstr
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
```
|
67
|
+
|
49
68
|
このコードの2行目で```Could not cast value of type 'UITableViewCell' (0x1a0fe4718) to 'weatherforecast_swift.CellForWeather' (0x100057828).```と出て落ちてしまいます。
|
50
69
|
|
51
70
|
**cell.xib**での**Identifier**は**cell_objec**tで、**CustomClass**は**CellForWeather**と確認しました。
|
52
71
|
|
53
|
-
|
72
|
+
追記2:if cell==nilの時の挙動を書かないといけないのだと思いますが、どのように書けばいいでしょうか?
|
54
73
|
|
55
|
-
ご教示お願い
|
74
|
+
ご教示お願いします
|
3
エラー追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,4 +21,35 @@
|
|
21
21
|
|
22
22
|
```
|
23
23
|
|
24
|
-
これと別のファイルで```cell = tableView.dequeueReusableCellWithIdentifier("cell_object") as? CustomTableViewCell```をして、Cellがnilの時のif文に```CustomTableViewCell.awakeFromNib()```と書きました。runすると、セルがnilだといって落ちてしまいます。どこを直せばいいでしょうか?ご教示おねがいします。
|
24
|
+
これと別のファイルで```cell = tableView.dequeueReusableCellWithIdentifier("cell_object") as? CustomTableViewCell```をして、Cellがnilの時のif文に```CustomTableViewCell.awakeFromNib()```と書きました。runすると、セルがnilだといって落ちてしまいます。どこを直せばいいでしょうか?ご教示おねがいします。
|
25
|
+
|
26
|
+
(追記)
|
27
|
+
|
28
|
+
```swift
|
29
|
+
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
|
30
|
+
|
31
|
+
let cell_object = tableView.dequeueReusableCellWithIdentifier("cell_object", forIndexPath: indexPath) as! CellForWeather
|
32
|
+
|
33
|
+
if (indexPath.row % 2 == 0) {
|
34
|
+
cell_object.backgroundColor = UIColor(hue:0.0,saturation:0.0,brightness:0.67,alpha:1.0)
|
35
|
+
}
|
36
|
+
// 奇数セル
|
37
|
+
else {
|
38
|
+
cell_object.backgroundColor = UIColor(hue:0.0,saturation:0.0,brightness:0.73,alpha:1.0)
|
39
|
+
}
|
40
|
+
|
41
|
+
// セルの向きを横向きに
|
42
|
+
cell_object.contentView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI) / 2);
|
43
|
+
|
44
|
+
CellForWeather().setdata("Tokyo",iconimg: UIImage(named:"01d.png")!)
|
45
|
+
return cell_object
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
このコードの2行目で```Could not cast value of type 'UITableViewCell' (0x1a0fe4718) to 'weatherforecast_swift.CellForWeather' (0x100057828).```と出て落ちてしまいます。
|
50
|
+
|
51
|
+
**cell.xib**での**Identifier**は**cell_objec**tで、**CustomClass**は**CellForWeather**と確認しました。
|
52
|
+
|
53
|
+
私の考えでは、returnするタイプがCellForWeatherではないかと思うのですが、するとDatasouceの方にエラーが出てしまいます。(多分間違っているのでしょう)
|
54
|
+
|
55
|
+
ご教示お願いいたします。
|
2
題名変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
=至急=swiftでのxibファイルの呼び出しでcellがnilになる(落ちる)
|
body
CHANGED
File without changes
|
1
題名の変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
xibファイルの呼び出し
|
1
|
+
<至急>swiftでのxibファイルの呼び出しでcellがnilになる(落ちる)
|
body
CHANGED
File without changes
|