質問編集履歴

4

意味がよくわかっていないコードがあったので、初心者マークをつけました。

2016/07/29 05:22

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
File without changes

3

Cell\.xibに変更しました。指摘してくださったfuzzballさま、ありがとうございました。

2016/07/29 05:22

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
@@ -334,7 +334,7 @@
334
334
 
335
335
  ###試したこと
336
336
 
337
- CellのIdentifierを確認しました。cell_objectになっていたので、合っていると思います。また、ViewWillAppearにしても同じ挙動が発生し、ダミーの情報に変えてみましたがそれも同じ挙動です。 やはりTableViewの読み込み時のCellがおかしいのでしょうか?なお、Cellはカスタムです。指摘してくださいました_Kentarou様、ありがとうございます。
337
+ Cell.xibのIdentifierを確認しました。cell_objectになっていたので、合っていると思います。また、ViewWillAppearにしても同じ挙動が発生し、ダミーの情報に変えてみましたがそれも同じ挙動です。 やはりTableViewの読み込み時のCellがおかしいのでしょうか?なお、Cellはカスタムです。指摘してくださいました_Kentarou様、ありがとうございます。
338
338
 
339
339
 
340
340
 

2

追記しました。

2016/07/29 04:30

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
@@ -8,13 +8,19 @@
8
8
 
9
9
 
10
10
 
11
- *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x16145a00; frame = (0 30; 414 140); transform = [0, -1, 1, 0, 0, 0]; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1568e200>; layer = <CALayer: 0x1568ded0>; contentOffset: {0, 0}; contentSize: {140, 7560}>) failed to obtain a cell from its dataSource (<VerticalTableViewCell: 0x16143a00; baseClass = UITableViewCell; frame = (0 170; 414 170); autoresize = W; layer = <CALayer: 0x1568d6d0>>)'
12
-
13
- *** First throw call stack:
14
-
15
- (0x22369b0b 0x21b26dff 0x223699e1 0x22b5073b 0x26a94663 0x26c91e89 0x26c91f61 0x26c8143d 0x26c96747 0x26a33a6f 0x269446fb 0x249b5569 0x249b0d2d 0x2695ad53 0x26a07039 0x26a04ccf 0x26a1dc23 0x26a1d983 0x26a1d6cf 0x269835e1 0x2698191d 0x26a106b5 0x26a0ffeb 0x26a06805 0x26a05aa7 0x26a05701 0x26a05677 0x269446fb 0x249b5569 0x249b0d2d 0x249b0bbd 0x249b0081 0x249afd55 0x249a94ff 0x2232b2b1 0x223295a7 0x222781e9 0x22277fbd 0x269b6f37 0x269b1435 0xbe34b 0x21f24873)
16
-
17
- libc++abi.dylib: terminating with uncaught exception of type NSException
11
+ ```ここに言語を入力
12
+
13
+ > *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x16145a00; frame = (0 30; 414 140); transform = [0, -1, 1, 0, 0, 0]; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1568e200>; layer = <CALayer: 0x1568ded0>; contentOffset: {0, 0}; contentSize: {140, 7560}>) failed to obtain a cell from its dataSource (<VerticalTableViewCell: 0x16143a00; baseClass = UITableViewCell; frame = (0 170; 414 170); autoresize = W; layer = <CALayer: 0x1568d6d0>>)'
14
+
15
+ > *** First throw call stack:
16
+
17
+ > (0x22369b0b 0x21b26dff 0x223699e1 0x22b5073b 0x26a94663 0x26c91e89 0x26c91f61 0x26c8143d 0x26c96747 0x26a33a6f 0x269446fb 0x249b5569 0x249b0d2d 0x2695ad53 0x26a07039 0x26a04ccf 0x26a1dc23 0x26a1d983 0x26a1d6cf 0x269835e1 0x2698191d 0x26a106b5 0x26a0ffeb 0x26a06805 0x26a05aa7 0x26a05701 0x26a05677 0x269446fb 0x249b5569 0x249b0d2d 0x249b0bbd 0x249b0081 0x249afd55 0x249a94ff 0x2232b2b1 0x223295a7 0x222781e9 0x22277fbd 0x269b6f37 0x269b1435 0xbe34b 0x21f24873)
18
+
19
+ > libc++abi.dylib: terminating with uncaught exception of type NSException
20
+
21
+ ```
22
+
23
+ failed to obtain a cell from its dataSource と書いてあるので、cellのidentifierが間違っているのかと思い、確認しましたが、ちゃんと書いてあります。
18
24
 
19
25
 
20
26
 
@@ -328,7 +334,7 @@
328
334
 
329
335
  ###試したこと
330
336
 
331
- CellのIdentifierを確認しました。cell_objectになっていたので、合っていると思います。
337
+ CellのIdentifierを確認しました。cell_objectになっていたので、合っていると思います。また、ViewWillAppearにしても同じ挙動が発生し、ダミーの情報に変えてみましたがそれも同じ挙動です。 やはりTableViewの読み込み時のCellがおかしいのでしょうか?なお、Cellはカスタムです。指摘してくださいました_Kentarou様、ありがとうございます。
332
338
 
333
339
 
334
340
 

1

誤字を修正しました。

2016/07/29 00:58

投稿

maplesugar_17
maplesugar_17

スコア32

test CHANGED
File without changes
test CHANGED
@@ -16,325 +16,319 @@
16
16
 
17
17
  libc++abi.dylib: terminating with uncaught exception of type NSException
18
18
 
19
+
20
+
21
+ ###該当のソースコード
22
+
23
+
24
+
25
+ ```ここに言語を入力
26
+
27
+ static NSString * const TableViewCustomCellIdentifier = @"Cell";
28
+
29
+
30
+
31
+ @implementation VerticalTableViewCell
32
+
33
+
34
+
35
+ -(void)awakeFromNib{
36
+
37
+ [super awakeFromNib];
38
+
39
+
40
+
41
+ UINib *nib = [UINib nibWithNibName:TableViewCustomCellIdentifier bundle:nil];
42
+
43
+ [self.horizontalTableView registerNib:nib forCellReuseIdentifier:@"Cell"];
44
+
45
+
46
+
47
+ if(imgcache){
48
+
49
+
50
+
51
+ }
52
+
53
+ else{
54
+
55
+ imgcache = [[NSCache alloc] init];
56
+
57
+ }
58
+
59
+ weather_icon = @{//day
60
+
61
+ @"01d":[UIImage imageNamed:@"01d.png"],
62
+
63
+ @"02d":[UIImage imageNamed:@"02d.png"],
64
+
65
+ @"03d":[UIImage imageNamed:@"03d.png"],
66
+
67
+ @"04d":[UIImage imageNamed:@"04d.png"],
68
+
69
+ @"09d":[UIImage imageNamed:@"09d.png"],
70
+
71
+ @"10d":[UIImage imageNamed:@"10d.png"],
72
+
73
+ @"11d":[UIImage imageNamed:@"11d.png"],
74
+
75
+ @"13d":[UIImage imageNamed:@"13d.png"],
76
+
77
+ @"50d":[UIImage imageNamed:@"50d.png"],
78
+
79
+ //night
80
+
81
+ @"01n":[UIImage imageNamed:@"01n.png"],
82
+
83
+ @"02n":[UIImage imageNamed:@"02n.png"],
84
+
85
+ @"03n":[UIImage imageNamed:@"03n.png"],
86
+
87
+ @"04n":[UIImage imageNamed:@"04n.png"],
88
+
89
+ @"09n":[UIImage imageNamed:@"09n.png"],
90
+
91
+ @"10n":[UIImage imageNamed:@"10n.png"],
92
+
93
+ @"11n":[UIImage imageNamed:@"11n.png"],
94
+
95
+ @"13n":[UIImage imageNamed:@"13n.png"],
96
+
97
+ @"50n":[UIImage imageNamed:@"50n.png"]};
98
+
99
+
100
+
101
+
102
+
103
+ // horizontalのセルを生成
104
+
105
+ static NSString *CellIdentifier = @"Cell";
106
+
107
+ Cell *cell_object = [table dequeueReusableCellWithIdentifier:CellIdentifier];
108
+
109
+
110
+
111
+ if(cell_object == nil){
112
+
113
+ cell_object = [Cell loadFromNib];
114
+
115
+ }
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ // この部分が重要
124
+
125
+ dispatch_queue_t q_global = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
126
+
127
+ dispatch_queue_t q_main = dispatch_get_main_queue();
128
+
129
+ cell_object.weather_icon_image.image = nil;
130
+
131
+
132
+
133
+ // 実行待ち
134
+
135
+ dispatch_async(q_global, ^{
136
+
137
+
138
+
139
+ NSRange searchResult = [self.weather_capital[indexp] rangeOfString:@"lat="];
140
+
141
+ if(searchResult.location == NSNotFound){
142
+
143
+ url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?APPID=b8f4ce09ae1ca4d1b34a14438e857866&q=%@", self.weather_capital[indexp]]];
144
+
145
+ }else{
146
+
147
+ url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?APPID=b8f4ce09ae1ca4d1b34a14438e857866&%@", self.weather_capital[indexp]]];
148
+
149
+ }
150
+
151
+
152
+
153
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
154
+
155
+
156
+
157
+ if(![imgcache objectForKey:url]){
158
+
159
+ [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
160
+
161
+ completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
162
+
163
+ if (data) {
164
+
165
+ NSDictionary *object = [NSJSONSerialization JSONObjectWithData:data options:
166
+
167
+
168
+
169
+
170
+
171
+ NSJSONReadingAllowFragments error:nil];
172
+
173
+
174
+
175
+ if (object) {
176
+
177
+ // ⑦ weather.mainの値を抽出
178
+
179
+ c++;
180
+
181
+ NSArray *main = [object valueForKeyPath:@"weather.main"]; //天候
182
+
183
+ NSArray *description = [object valueForKeyPath:@"weather.description"]; // 天候詳細
184
+
185
+ NSArray *speed = [object valueForKeyPath:@"wind.speed"]; //風速
186
+
187
+ NSArray *icons = [object valueForKeyPath:@"weather.icon"];
188
+
189
+ NSArray *names = [object valueForKeyPath:@"name"];
190
+
191
+
192
+
193
+ NSLog(@"main(天候)=%@,description(天候詳細)=%@,speed(風速)=%@,icons(天気アイコン)=%@,name=%@",main,description,speed,icons,names);
194
+
195
+
196
+
197
+ NSMutableDictionary *weather= @{@"main":main,
198
+
199
+ @"description":description,
200
+
201
+ @"speed":speed,
202
+
203
+ @"icons":icons,
204
+
205
+ @"names":names}.mutableCopy;
206
+
207
+ dispatch_async(q_main, ^{
208
+
209
+ NSString *imageKeyname = weather[@"icons"][0];
210
+
211
+ cell_object.weather_icon_image.image = weather_icon[imageKeyname];
212
+
213
+ iconimg = weather_icon[imageKeyname];
214
+
215
+ [imgcache setObject:iconimg forKey:url];
216
+
217
+ [cell_object layoutSubviews];
218
+
219
+ NSString *cityname = weather[@"names"];
220
+
221
+ cell_object.title.text = cityname;
222
+
223
+ });
224
+
225
+ }else {
226
+
227
+
228
+
229
+ }
230
+
231
+ }else {
232
+
233
+ NSLog(@"レスポンス == %@, エラー == %@", response, error);
234
+
235
+ }
236
+
237
+ }];
238
+
239
+
240
+
241
+ }
242
+
243
+ else{
244
+
245
+ NSLog(@"cache...%@",imgcache);
246
+
247
+ cell_object.weather_icon_image.image = [imgcache objectForKey:url];
248
+
249
+ }
250
+
251
+ });
252
+
253
+
254
+
255
+ cell_object.title.text = [NSString stringWithFormat:@"%@",_weather_capital[indexp]];
256
+
257
+
258
+
259
+ table.separatorStyle = UITableViewCellSeparatorStyleNone;
260
+
261
+ table.bounces = YES;
262
+
263
+
264
+
265
+ if (indexp % 2 == 0) {
266
+
267
+ cell_object.backgroundColor = [UIColor colorWithHue:0.0
268
+
269
+ saturation:0.0
270
+
271
+ brightness:0.67
272
+
273
+ alpha:1.0];
274
+
275
+ }
276
+
277
+ // 奇数セル
278
+
279
+ else {
280
+
281
+ cell_object.backgroundColor = [UIColor colorWithHue:0.0
282
+
283
+ saturation:0.0
284
+
285
+ brightness:0.73
286
+
287
+ alpha:1.0];
288
+
289
+ }
290
+
291
+
292
+
293
+ // セルの向きを横向きに
294
+
295
+ cell_object.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
296
+
297
+ NSLog(@"%d",c);
298
+
299
+
300
+
301
+
302
+
303
+ }
304
+
305
+
306
+
307
+ -(Cell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
308
+
309
+ {
310
+
311
+ static NSString *CellIdentifier = @"Cell";
312
+
313
+ Cell *cell_object = [table dequeueReusableCellWithIdentifier:CellIdentifier];
314
+
315
+ table = tableView;
316
+
317
+ indexp = indexPath.row;
318
+
319
+ return cell_object;
320
+
321
+ }
322
+
323
+
324
+
19
325
  ```
20
326
 
21
- ```
22
-
23
- ```
24
-
25
- ###該当のソースコード
26
-
27
-
28
-
29
- ```ここに言語を入力
30
-
31
- static NSString * const TableViewCustomCellIdentifier = @"Cell";
32
-
33
-
34
-
35
- @implementation VerticalTableViewCell
36
-
37
-
38
-
39
- -(void)awakeFromNib{
40
-
41
- [super awakeFromNib];
42
-
43
-
44
-
45
- UINib *nib = [UINib nibWithNibName:TableViewCustomCellIdentifier bundle:nil];
46
-
47
- [self.horizontalTableView registerNib:nib forCellReuseIdentifier:@"Cell"];
48
-
49
-
50
-
51
- if(imgcache){
52
-
53
-
54
-
55
- }
56
-
57
- else{
58
-
59
- imgcache = [[NSCache alloc] init];
60
-
61
- }
62
-
63
- weather_icon = @{//day
64
-
65
- @"01d":[UIImage imageNamed:@"01d.png"],
66
-
67
- @"02d":[UIImage imageNamed:@"02d.png"],
68
-
69
- @"03d":[UIImage imageNamed:@"03d.png"],
70
-
71
- @"04d":[UIImage imageNamed:@"04d.png"],
72
-
73
- @"09d":[UIImage imageNamed:@"09d.png"],
74
-
75
- @"10d":[UIImage imageNamed:@"10d.png"],
76
-
77
- @"11d":[UIImage imageNamed:@"11d.png"],
78
-
79
- @"13d":[UIImage imageNamed:@"13d.png"],
80
-
81
- @"50d":[UIImage imageNamed:@"50d.png"],
82
-
83
- //night
84
-
85
- @"01n":[UIImage imageNamed:@"01n.png"],
86
-
87
- @"02n":[UIImage imageNamed:@"02n.png"],
88
-
89
- @"03n":[UIImage imageNamed:@"03n.png"],
90
-
91
- @"04n":[UIImage imageNamed:@"04n.png"],
92
-
93
- @"09n":[UIImage imageNamed:@"09n.png"],
94
-
95
- @"10n":[UIImage imageNamed:@"10n.png"],
96
-
97
- @"11n":[UIImage imageNamed:@"11n.png"],
98
-
99
- @"13n":[UIImage imageNamed:@"13n.png"],
100
-
101
- @"50n":[UIImage imageNamed:@"50n.png"]};
102
-
103
-
104
-
105
-
106
-
107
- // horizontalのセルを生成
108
-
109
- static NSString *CellIdentifier = @"Cell";
110
-
111
- Cell *cell_object = [table dequeueReusableCellWithIdentifier:CellIdentifier];
112
-
113
-
114
-
115
- if(cell_object == nil){
116
-
117
- cell_object = [Cell loadFromNib];
118
-
119
- }
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
- // この部分が重要
128
-
129
- dispatch_queue_t q_global = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
130
-
131
- dispatch_queue_t q_main = dispatch_get_main_queue();
132
-
133
- cell_object.weather_icon_image.image = nil;
134
-
135
-
136
-
137
- // 実行待ち
138
-
139
- dispatch_async(q_global, ^{
140
-
141
-
142
-
143
- NSRange searchResult = [self.weather_capital[indexp] rangeOfString:@"lat="];
144
-
145
- if(searchResult.location == NSNotFound){
146
-
147
- url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?APPID=b8f4ce09ae1ca4d1b34a14438e857866&q=%@", self.weather_capital[indexp]]];
148
-
149
- }else{
150
-
151
- url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?APPID=b8f4ce09ae1ca4d1b34a14438e857866&%@", self.weather_capital[indexp]]];
152
-
153
- }
154
-
155
-
156
-
157
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
158
-
159
-
160
-
161
- if(![imgcache objectForKey:url]){
162
-
163
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
164
-
165
- completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
166
-
167
- if (data) {
168
-
169
- NSDictionary *object = [NSJSONSerialization JSONObjectWithData:data options:
170
-
171
-
172
-
173
-
174
-
175
- NSJSONReadingAllowFragments error:nil];
176
-
177
-
178
-
179
- if (object) {
180
-
181
- // ⑦ weather.mainの値を抽出
182
-
183
- c++;
184
-
185
- NSArray *main = [object valueForKeyPath:@"weather.main"]; //天候
186
-
187
- NSArray *description = [object valueForKeyPath:@"weather.description"]; // 天候詳細
188
-
189
- NSArray *speed = [object valueForKeyPath:@"wind.speed"]; //風速
190
-
191
- NSArray *icons = [object valueForKeyPath:@"weather.icon"];
192
-
193
- NSArray *names = [object valueForKeyPath:@"name"];
194
-
195
-
196
-
197
- NSLog(@"main(天候)=%@,description(天候詳細)=%@,speed(風速)=%@,icons(天気アイコン)=%@,name=%@",main,description,speed,icons,names);
198
-
199
-
200
-
201
- NSMutableDictionary *weather= @{@"main":main,
202
-
203
- @"description":description,
204
-
205
- @"speed":speed,
206
-
207
- @"icons":icons,
208
-
209
- @"names":names}.mutableCopy;
210
-
211
- dispatch_async(q_main, ^{
212
-
213
- NSString *imageKeyname = weather[@"icons"][0];
214
-
215
- cell_object.weather_icon_image.image = weather_icon[imageKeyname];
216
-
217
- iconimg = weather_icon[imageKeyname];
218
-
219
- [imgcache setObject:iconimg forKey:url];
220
-
221
- [cell_object layoutSubviews];
222
-
223
- NSString *cityname = weather[@"names"];
224
-
225
- cell_object.title.text = cityname;
226
-
227
- });
228
-
229
- }else {
230
-
231
- // TODO: ここに取得できなかったときの処理。でも本当は、「すでに取れてたらリクエストを送らない」というのが正解
232
-
233
-
234
-
235
- }
236
-
237
- }else {
238
-
239
- NSLog(@"レスポンス == %@, エラー == %@", response, error);
240
-
241
- }
242
-
243
- }];
244
-
245
-
246
-
247
- }
248
-
249
- else{
250
-
251
- NSLog(@"cache...%@",imgcache);
252
-
253
- cell_object.weather_icon_image.image = [imgcache objectForKey:url];
254
-
255
- }
256
-
257
- });
258
-
259
-
260
-
261
- cell_object.title.text = [NSString stringWithFormat:@"%@",_weather_capital[indexp]];
262
-
263
-
264
-
265
- table.separatorStyle = UITableViewCellSeparatorStyleNone;
266
-
267
- table.bounces = YES;
268
-
269
-
270
-
271
- if (indexp % 2 == 0) {
272
-
273
- cell_object.backgroundColor = [UIColor colorWithHue:0.0
274
-
275
- saturation:0.0
276
-
277
- brightness:0.67
278
-
279
- alpha:1.0];
280
-
281
- }
282
-
283
- // 奇数セル
284
-
285
- else {
286
-
287
- cell_object.backgroundColor = [UIColor colorWithHue:0.0
288
-
289
- saturation:0.0
290
-
291
- brightness:0.73
292
-
293
- alpha:1.0];
294
-
295
- }
296
-
297
-
298
-
299
- // セルの向きを横向きに
300
-
301
- cell_object.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
302
-
303
- NSLog(@"%d",c);
304
-
305
-
306
-
307
-
308
-
309
- }
310
-
311
-
312
-
313
- -(Cell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
314
-
315
- {
316
-
317
- static NSString *CellIdentifier = @"Cell";
318
-
319
- Cell *cell_object = [table dequeueReusableCellWithIdentifier:CellIdentifier];
320
-
321
- table = tableView;
322
-
323
- indexp = indexPath.row;
324
-
325
- return cell_object;
326
-
327
- }
328
-
329
-
330
-
331
- ```
332
-
333
327
 
334
328
 
335
329
  ###試したこと
336
330
 
337
- CellのIdentifierを確認しました。cell_objectになっていたので、っていると思います。
331
+ CellのIdentifierを確認しました。cell_objectになっていたので、っていると思います。
338
332
 
339
333
 
340
334