質問するログイン新規登録

質問編集履歴

11

プログラムの修正

2018/11/15 14:09

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -65,6 +65,7 @@
65
65
  self.dates = [[NSMutableArray alloc] init];
66
66
  self.realTemperatures = [[NSMutableArray alloc] init];
67
67
  self.damiTemperatures = [[NSMutableArray alloc] init];
68
+ self.array = [[NSMutableArray alloc] init];
68
69
 
69
70
  // DelegateとDataSourceはstoryboard(またはxib)のところで結び付けるのでもO.K.
70
71
  _tblView.delegate = self;
@@ -82,7 +83,6 @@
82
83
  {
83
84
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
84
85
  // query.skip = 4;
85
-   //クエリを取得順に
86
86
  [query orderByDescending:@"createDate"];
87
87
  query.limit = 40;
88
88
  [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error)
@@ -122,8 +122,9 @@
122
122
  }
123
123
 
124
124
  }
125
- [self.tblView reloadData];
125
+
126
126
  }
127
+ [self.tblView reloadData];
127
128
  }
128
129
 
129
130
 
@@ -141,11 +142,18 @@
141
142
  // セル数
142
143
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
143
144
 
144
- return [self.amountwaters count];
145
+ return [self.array count];
145
146
 
146
147
  }
147
148
 
148
149
 
150
+ /*
151
+ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
152
+
153
+ return [self.amountwaters count];
154
+
155
+ }
156
+ */
149
157
  // セルの内容を設定
150
158
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
151
159
 

10

コメント追加

2018/11/15 14:09

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -82,6 +82,7 @@
82
82
  {
83
83
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
84
84
  // query.skip = 4;
85
+   //クエリを取得順に
85
86
  [query orderByDescending:@"createDate"];
86
87
  query.limit = 40;
87
88
  [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error)
@@ -236,7 +237,7 @@
236
237
  | value| || value | value || ||2018-11-15T21:29:37.942+09:00|
237
238
  | |11/15|| | | ||value ||2018-11-15T21:29:37.942+09:00|
238
239
  | value| || value | value || ||2018-11-15T21:29:37.942+09:00|
239
- //以下省略しています
240
+ //以下省略しています,valueには何かしらの値が入っています
240
241
  ### 試したこと
241
242
 
242
243
  NSLogを用いてデータが検索できているかどうか調べましたが、mBassからの検索はできています。

9

DBの中身追加しました

2018/11/15 13:11

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -230,6 +230,13 @@
230
230
  @end
231
231
 
232
232
  ```
233
+ //DBの中身
234
+ |damileaf|date|hikakuleaf||kaerumsg||water||createDate|
235
+ | |11/15|| | | ||value ||2018-11-15T21:29:37.942+09:00|
236
+ | value| || value | value || ||2018-11-15T21:29:37.942+09:00|
237
+ | |11/15|| | | ||value ||2018-11-15T21:29:37.942+09:00|
238
+ | value| || value | value || ||2018-11-15T21:29:37.942+09:00|
239
+ //以下省略しています
233
240
  ### 試したこと
234
241
 
235
242
  NSLogを用いてデータが検索できているかどうか調べましたが、mBassからの検索はできています。

8

プログラム修正

2018/11/15 13:07

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -49,7 +49,6 @@
49
49
 
50
50
  }
51
51
 
52
-
53
52
  @end
54
53
 
55
54
  // テーブル表示件数
@@ -66,127 +65,71 @@
66
65
  self.dates = [[NSMutableArray alloc] init];
67
66
  self.realTemperatures = [[NSMutableArray alloc] init];
68
67
  self.damiTemperatures = [[NSMutableArray alloc] init];
68
+
69
69
  // DelegateとDataSourceはstoryboard(またはxib)のところで結び付けるのでもO.K.
70
70
  _tblView.delegate = self;
71
71
  _tblView.dataSource = self;
72
-
72
+
73
73
  // カスタムセルを使用
74
74
  UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
75
75
  [_tblView registerNib:nib forCellReuseIdentifier:@"Cell"];
76
76
 
77
- //保存したデータの検索と取得
78
- [self setupData1];
77
+ [self kaeruQuery];
79
- [self setupData2];
80
- [self setupData3];
81
- [self setupData4];
82
- [self setupData5];
83
78
 
84
79
 
85
80
  }
86
-
87
- - (void)setupData1 {
81
+ -(void)kaeruQuery
82
+ {
88
83
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
89
- // 検索件数を設定
84
+ // query.skip = 4;
85
+ [query orderByDescending:@"createDate"];
90
- query.limit = 10;
86
+ query.limit = 40;
91
- [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
92
- // [query whereKey:@"water" notEqualTo:[NSNull null]];
93
-
94
- [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
87
+ [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error)
95
- if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
88
+ {
96
- if (!error) {
89
+ if (!error) {
97
- for (NCMBObject *object in objects) {
90
+ for (NCMBObject *obj in array) {
91
+ {
92
+ if ([obj objectForKey:@"kaerumsg"]) {
93
+ NSMutableArray* hoge1;
98
- NSMutableArray *hoge1 = [object objectForKey:@"kaerumsg"];
94
+ hoge1 = [obj objectForKey:@"kaerumsg"];
99
- // NSMutableArray *hoge2 = [object objectForKey:@"water"];
100
-
101
- [self.msgs addObject:hoge1];
95
+ [self.msgs addObject:hoge1];
102
- NSLog(@"%@",self.msgs);
96
+ NSLog(@"%@",self.msgs);
103
- }
97
+ }
98
+ if ([obj objectForKey:@"water"]) {
99
+ NSMutableArray* hoge2;
100
+ hoge2 = [obj objectForKey:@"water"];
101
+ [self.amountwaters addObject:hoge2];
102
+ NSLog(@"%@",self.amountwaters);
103
+ }
104
+ if ([obj objectForKey:@"date"]) {
105
+ NSMutableArray* hoge3;
106
+ hoge3 = [obj objectForKey:@"date"];
107
+ [self.dates addObject:hoge3];
108
+ NSLog(@"%@",self.dates);
109
+ }
110
+ if ([obj objectForKey:@"hikakuleaf"]) {
111
+ NSMutableArray *hoge4;
112
+ hoge4 = [obj objectForKey:@"hikakuleaf"];
113
+ [self.realTemperatures addObject:hoge4];
114
+ NSLog(@"%@",self.realTemperatures);
115
+ }
116
+ if ([obj objectForKey:@"damileaf"]) {
117
+ NSMutableArray *hoge5;
118
+ hoge5 = [obj objectForKey:@"damileaf"];
119
+ [self.damiTemperatures addObject:hoge5];
120
+ NSLog(@"%@",self.realTemperatures);
121
+ }
122
+
123
+ }
104
- [self.tblView reloadData];
124
+ [self.tblView reloadData];
105
- }
125
+ }
106
- }
126
+ }
127
+
128
+
107
- }];
129
+ }];
108
130
  }
109
131
 
110
- - (void)setupData2 {
111
- NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
112
- // 検索件数を設定
113
- query.limit = 10;
114
- [query whereKey:@"water" notEqualTo:[NSNull null]];
115
-
116
- [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
117
- if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
118
- if (!error) {
119
- for (NCMBObject *object in objects) {
120
- NSMutableArray *hoge2 = [object objectForKey:@"water"];
121
- [self.amountwaters addObject:hoge2];
122
- NSLog(@"%@",self.amountwaters);
123
- }
124
- [self.tblView reloadData];
125
- }
126
- }
127
- }];
128
- }
129
132
 
130
- - (void)setupData3 {
131
- NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
132
- // 検索件数を設定
133
- query.limit = 10;
134
- [query whereKey:@"date" notEqualTo:[NSNull null]];
135
-
136
- [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
137
- if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
138
- if (!error) {
139
- for (NCMBObject *object in objects) {
140
- NSMutableArray *hoge3 = [object objectForKey:@"date"];
141
- [self.dates addObject:hoge3];
142
- NSLog(@"%@",self.dates);
143
- }
144
- [self.tblView reloadData];
145
- }
146
- }
147
- }];
148
- }
149
- - (void)setupData4 {
150
- NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
151
- // 検索件数を設定
152
- query.limit = 10;
153
- [query whereKey:@"hikakuleaf" notEqualTo:[NSNull null]];
154
-
155
- [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
156
- if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
157
- if (!error) {
158
- for (NCMBObject *object in objects) {
159
- NSMutableArray *hoge4 = [object objectForKey:@"hikakuleaf"];
160
- [self.realTemperatures addObject:hoge4];
161
- NSLog(@"%@",self.realTemperatures);
162
- }
163
- [self.tblView reloadData];
164
- }
165
- }
166
- }];
167
- }
168
-
169
- - (void)setupData5 {
170
- NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
171
- // 検索件数を設定
172
- query.limit = 10;
173
- [query whereKey:@"damileaf" notEqualTo:[NSNull null]];
174
-
175
- [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
176
- if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
177
- if (!error) {
178
- for (NCMBObject *object in objects) {
179
- NSMutableArray *hoge5 = [object objectForKey:@"damileaf"];
180
- [self.damiTemperatures addObject:hoge5];
181
- NSLog(@"%@",self.damiTemperatures);
182
- }
183
- [self.tblView reloadData];
184
- }
185
- }
186
- }];
187
- }
188
-
189
-
190
133
  #pragma mark UITableView
191
134
 
192
135
  // セクション数
@@ -196,7 +139,7 @@
196
139
 
197
140
  // セル数
198
141
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
199
-
142
+
200
143
  return [self.amountwaters count];
201
144
 
202
145
  }
@@ -216,12 +159,20 @@
216
159
  cell.realTemperature.numberOfLines = 0;
217
160
  cell.msg.numberOfLines = 0;
218
161
 
162
+
219
163
  cell.msg.text = [self.msgs objectAtIndex:indexPath.row];
220
164
  cell.amountwater.text = [self.amountwaters objectAtIndex:indexPath.row];
221
165
  cell.date.text = [self.dates objectAtIndex:indexPath.row];
222
166
  cell.realTemperature.text = [self.realTemperatures objectAtIndex:indexPath.row];
223
167
  cell.damiTemperature.text = [self.damiTemperatures objectAtIndex:indexPath.row];
168
+
224
-
169
+ /*
170
+ cell.msg.text = self.msgs [indexPath.row];
171
+ cell.amountwater.text = self.amountwaters [indexPath.row];
172
+ cell.date.text = self.dates [indexPath.row];
173
+ cell.realTemperature.text = self.realTemperatures [indexPath.row];
174
+ cell.damiTemperature.text = self.damiTemperatures [indexPath.row];*/
175
+
225
176
  return cell;
226
177
  }
227
178
 
@@ -232,7 +183,7 @@
232
183
 
233
184
  //dequeueReusableCellWithIdentifier(セルを使用する)
234
185
  CustomCell *Cell = [self.tblView dequeueReusableCellWithIdentifier:@"Cell"];
235
-
186
+
236
187
  //とりあえず固定値に
237
188
  return 200;
238
189
  }
@@ -277,6 +228,7 @@
277
228
  }
278
229
 
279
230
  @end
231
+
280
232
  ```
281
233
  ### 試したこと
282
234
 

7

プログラム変更

2018/11/15 12:59

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -48,8 +48,8 @@
48
48
  {
49
49
 
50
50
  }
51
- @property (strong,nonatomic)NSMutableArray *vals;
52
51
 
52
+
53
53
  @end
54
54
 
55
55
  // テーブル表示件数
@@ -61,50 +61,132 @@
61
61
 
62
62
  - (void)viewDidLoad {
63
63
  [super viewDidLoad];
64
+ self.msgs = [[NSMutableArray alloc] init];
65
+ self.amountwaters = [[NSMutableArray alloc] init];
66
+ self.dates = [[NSMutableArray alloc] init];
67
+ self.realTemperatures = [[NSMutableArray alloc] init];
68
+ self.damiTemperatures = [[NSMutableArray alloc] init];
64
69
  // DelegateとDataSourceはstoryboard(またはxib)のところで結び付けるのでもO.K.
65
70
  _tblView.delegate = self;
66
71
  _tblView.dataSource = self;
67
- self.msgs = [[NSMutableArray alloc] init];
68
72
 
69
73
  // カスタムセルを使用
70
74
  UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
71
75
  [_tblView registerNib:nib forCellReuseIdentifier:@"Cell"];
72
76
 
73
77
  //保存したデータの検索と取得
74
- [self setupData];
78
+ [self setupData1];
79
+ [self setupData2];
80
+ [self setupData3];
81
+ [self setupData4];
82
+ [self setupData5];
75
83
 
84
+
76
85
  }
77
86
 
87
+ - (void)setupData1 {
88
+ NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
78
- //【mBaaS】保存したデータの検索と取得
89
+ // 検索件数を設定
90
+ query.limit = 10;
91
+ [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
92
+ // [query whereKey:@"water" notEqualTo:[NSNull null]];
93
+
94
+ [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
95
+ if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
96
+ if (!error) {
97
+ for (NCMBObject *object in objects) {
98
+ NSMutableArray *hoge1 = [object objectForKey:@"kaerumsg"];
99
+ // NSMutableArray *hoge2 = [object objectForKey:@"water"];
100
+
101
+ [self.msgs addObject:hoge1];
102
+ NSLog(@"%@",self.msgs);
103
+ }
104
+ [self.tblView reloadData];
105
+ }
106
+ }
107
+ }];
108
+ }
79
109
 
80
- - (void)setupData {
110
+ - (void)setupData2 {
81
- // GameScoreクラスを検索するクエリを作成
82
- NCMBQuery *query = [NCMBQuery queryWithClassName:@"HOGEHOGE"];
111
+ NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
83
112
  // 検索件数を設定
84
- query.limit = 20;
113
+ query.limit = 10;
114
+ [query whereKey:@"water" notEqualTo:[NSNull null]];
115
+
116
+ [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
117
+ if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
118
+ if (!error) {
119
+ for (NCMBObject *object in objects) {
120
+ NSMutableArray *hoge2 = [object objectForKey:@"water"];
121
+ [self.amountwaters addObject:hoge2];
122
+ NSLog(@"%@",self.amountwaters);
123
+ }
124
+ [self.tblView reloadData];
125
+ }
126
+ }
127
+ }];
128
+ }
85
129
 
130
+ - (void)setupData3 {
131
+ NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
132
+ // 検索件数を設定
133
+ query.limit = 10;
86
- [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
134
+ [query whereKey:@"date" notEqualTo:[NSNull null]];
87
- //データストアを検索
135
+
88
136
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
137
+ if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
89
- if (error) {
138
+ if (!error) {
90
- // 検索に失敗した場合の処理
91
- NSLog(@"検索に失敗しました。エラーコード:%ld", error.code);
92
- } else {
93
- // 検索に成功した場合の処理
94
- NSLog(@"検索に成功しました。");
95
- //[self.msgs removeAllObjects];
96
- for (NCMBObject *object in objects){
139
+ for (NCMBObject *object in objects) {
97
- [self.msgs addObject:[object objectForKey:@"kaerumsg"]];
140
+ NSMutableArray *hoge3 = [object objectForKey:@"date"];
141
+ [self.dates addObject:hoge3];
98
- NSLog(@"%@",self.msgs);
142
+ NSLog(@"%@",self.dates);
99
143
  }
100
-
144
+ [self.tblView reloadData];
101
145
  }
102
-
146
+ }
103
147
  }];
104
- // **************************************************
105
- //
106
148
  }
149
+ - (void)setupData4 {
150
+ NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
151
+ // 検索件数を設定
152
+ query.limit = 10;
153
+ [query whereKey:@"hikakuleaf" notEqualTo:[NSNull null]];
154
+
155
+ [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
156
+ if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
157
+ if (!error) {
158
+ for (NCMBObject *object in objects) {
159
+ NSMutableArray *hoge4 = [object objectForKey:@"hikakuleaf"];
160
+ [self.realTemperatures addObject:hoge4];
161
+ NSLog(@"%@",self.realTemperatures);
162
+ }
163
+ [self.tblView reloadData];
164
+ }
165
+ }
166
+ }];
167
+ }
107
168
 
169
+ - (void)setupData5 {
170
+ NCMBQuery *query = [NCMBQuery queryWithClassName:@"HAGE"];
171
+ // 検索件数を設定
172
+ query.limit = 10;
173
+ [query whereKey:@"damileaf" notEqualTo:[NSNull null]];
174
+
175
+ [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
176
+ if (objects!= nil && [objects isKindOfClass:[NSArray class]]){
177
+ if (!error) {
178
+ for (NCMBObject *object in objects) {
179
+ NSMutableArray *hoge5 = [object objectForKey:@"damileaf"];
180
+ [self.damiTemperatures addObject:hoge5];
181
+ NSLog(@"%@",self.damiTemperatures);
182
+ }
183
+ [self.tblView reloadData];
184
+ }
185
+ }
186
+ }];
187
+ }
188
+
189
+
108
190
  #pragma mark UITableView
109
191
 
110
192
  // セクション数
@@ -114,7 +196,9 @@
114
196
 
115
197
  // セル数
116
198
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
199
+
117
- return 20;
200
+ return [self.amountwaters count];
201
+
118
202
  }
119
203
 
120
204
 
@@ -125,9 +209,19 @@
125
209
 
126
210
  // カスタムセルを取得
127
211
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
212
+
213
+ cell.date.numberOfLines = 0;
214
+ cell.amountwater.numberOfLines = 0;
215
+ cell.damiTemperature.numberOfLines = 0;
216
+ cell.realTemperature.numberOfLines = 0;
217
+ cell.msg.numberOfLines = 0;
218
+
219
+ cell.msg.text = [self.msgs objectAtIndex:indexPath.row];
220
+ cell.amountwater.text = [self.amountwaters objectAtIndex:indexPath.row];
221
+ cell.date.text = [self.dates objectAtIndex:indexPath.row];
222
+ cell.realTemperature.text = [self.realTemperatures objectAtIndex:indexPath.row];
223
+ cell.damiTemperature.text = [self.damiTemperatures objectAtIndex:indexPath.row];
128
224
 
129
- cell.msg.text = self.msgs[indexPath.row];
130
-
131
225
  return cell;
132
226
  }
133
227
 
@@ -148,6 +242,7 @@
148
242
  * @param text 文字列
149
243
  * @return CGFloat 高さ
150
244
  */
245
+
151
246
  - (CGFloat)calcHeight:(NSString *)text {
152
247
 
153
248
  // 端末サイズ取得
@@ -168,6 +263,7 @@
168
263
  return rect.size.height;
169
264
  }
170
265
 
266
+
171
267
  // セル押下時の処理
172
268
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
173
269
 
@@ -181,7 +277,6 @@
181
277
  }
182
278
 
183
279
  @end
184
-
185
280
  ```
186
281
  ### 試したこと
187
282
 

6

文法の訂正

2018/11/14 09:45

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -94,7 +94,7 @@
94
94
  NSLog(@"検索に成功しました。");
95
95
  //[self.msgs removeAllObjects];
96
96
  for (NCMBObject *object in objects){
97
- [msgs addObject:[object objectForKey:@"kaerumsg"]];
97
+ [self.msgs addObject:[object objectForKey:@"kaerumsg"]];
98
98
  NSLog(@"%@",self.msgs);
99
99
  }
100
100
 

5

プログラムの訂正

2018/11/13 11:39

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -94,8 +94,8 @@
94
94
  NSLog(@"検索に成功しました。");
95
95
  //[self.msgs removeAllObjects];
96
96
  for (NCMBObject *object in objects){
97
- self.msgs = [object objectForKey:@"kaerumsg"];
97
+ [msgs addObject:[object objectForKey:@"kaerumsg"]];
98
- NSLog(@"%@",self.msgs);
98
+ NSLog(@"%@",self.msgs);
99
99
  }
100
100
 
101
101
  }

4

プログラムの訂正

2018/11/13 11:38

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -47,25 +47,16 @@
47
47
  @interface SecandViewController ()<UITableViewDataSource, UITableViewDelegate>
48
48
  {
49
49
 
50
-
51
- // NSMutableArray *waters;
52
- // NSMutableArray *msgs;
53
50
  }
54
- @property (retain, nonatomic)NSMutableArray *msgs;
51
+ @property (strong,nonatomic)NSMutableArray *vals;
55
52
 
56
-
57
53
  @end
58
54
 
59
55
  // テーブル表示件数
60
56
  //const NSInteger historyNumber = 100;
61
57
 
62
58
  @implementation SecandViewController
63
- - (NSMutableArray *)msgs{
59
+
64
- if (!_msgs) {
65
- _msgs = [[NSMutableArray alloc] init];
66
- }
67
- return _msgs;
68
- }
69
60
  #pragma mark Life Cycle
70
61
 
71
62
  - (void)viewDidLoad {
@@ -73,7 +64,8 @@
73
64
  // DelegateとDataSourceはstoryboard(またはxib)のところで結び付けるのでもO.K.
74
65
  _tblView.delegate = self;
75
66
  _tblView.dataSource = self;
76
-
67
+ self.msgs = [[NSMutableArray alloc] init];
68
+
77
69
  // カスタムセルを使用
78
70
  UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
79
71
  [_tblView registerNib:nib forCellReuseIdentifier:@"Cell"];
@@ -92,9 +84,6 @@
92
84
  query.limit = 20;
93
85
 
94
86
  [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
95
- // [query whereKey:@"water" notEqualTo:[NSNull null]];
96
- // [query whereKey:@"water" notEqualTo:[NSNull null]];
97
- // [query orderByAscending:@"kaerumsg"];
98
87
  //データストアを検索
99
88
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
100
89
  if (error) {
@@ -105,13 +94,8 @@
105
94
  NSLog(@"検索に成功しました。");
106
95
  //[self.msgs removeAllObjects];
107
96
  for (NCMBObject *object in objects){
108
- // vals = [object objectForKey:@"kaerumsg"];
109
- // [self.msgs addObject:vals];
110
- [_msgs addObject:[object objectForKey:@"kaerumsg"]];
97
+ self.msgs = [object objectForKey:@"kaerumsg"];
111
- // NSLog(@"%@",vals);
112
- NSLog(@"%@",_msgs);
98
+ NSLog(@"%@",self.msgs);
113
- // [waters addObject:[object objectForKey:@"water"]];
114
- // NSLog(@"%@",waters);
115
99
  }
116
100
 
117
101
  }
@@ -142,12 +126,8 @@
142
126
  // カスタムセルを取得
143
127
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
144
128
 
145
- cell.msg.numberOfLines = 0;
146
- // cell.amountwater.numberOfLines = 0;
147
-
148
- // cell.msg.text = (NSString*)msgs;
149
- cell.msg.text = _msgs[indexPath.row];
129
+ cell.msg.text = self.msgs[indexPath.row];
150
- // cell.amountwater.text = waters[indexPath.row];
130
+
151
131
  return cell;
152
132
  }
153
133
 
@@ -202,7 +182,6 @@
202
182
 
203
183
  @end
204
184
 
205
-
206
185
  ```
207
186
  ### 試したこと
208
187
 

3

ヘッダーファイルの追加

2018/11/13 11:12

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -15,7 +15,28 @@
15
15
 
16
16
  ### 該当のソースコード
17
17
 
18
+
19
+ ```
20
+ //hファイルです。
21
+ #import <UIKit/UIKit.h>
22
+ #import "TransitionObj.h"
23
+ #import "CustomCell.h"
24
+
25
+ @interface SecandViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
26
+
27
+ //@property (weak, nonatomic) IBOutlet UILabel *l1v;
28
+ @property (strong, nonatomic) TransitionObj* transitionObj;
29
+ //@property (weak, nonatomic) IBOutlet UITextField *f2v;
30
+
31
+ // テーブルビュー
32
+ @property (weak, nonatomic) IBOutlet UITableView *tblView;
33
+
34
+
35
+ @end
36
+
37
+ ```
18
38
  ```Objective-C
39
+ //mファイルです。
19
40
  #import <Foundation/Foundation.h>
20
41
  #import "SecandViewController.h"
21
42
  #import "TransitionObj.h"
@@ -26,16 +47,25 @@
26
47
  @interface SecandViewController ()<UITableViewDataSource, UITableViewDelegate>
27
48
  {
28
49
 
50
+
51
+ // NSMutableArray *waters;
29
- NSMutableArray *msgs;
52
+ // NSMutableArray *msgs;
30
53
  }
54
+ @property (retain, nonatomic)NSMutableArray *msgs;
31
55
 
56
+
32
57
  @end
33
58
 
34
59
  // テーブル表示件数
35
60
  //const NSInteger historyNumber = 100;
36
61
 
37
62
  @implementation SecandViewController
38
-
63
+ - (NSMutableArray *)msgs{
64
+ if (!_msgs) {
65
+ _msgs = [[NSMutableArray alloc] init];
66
+ }
67
+ return _msgs;
68
+ }
39
69
  #pragma mark Life Cycle
40
70
 
41
71
  - (void)viewDidLoad {
@@ -56,13 +86,15 @@
56
86
  //【mBaaS】保存したデータの検索と取得
57
87
 
58
88
  - (void)setupData {
59
-
60
89
  // GameScoreクラスを検索するクエリを作成
61
90
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HOGEHOGE"];
62
91
  // 検索件数を設定
63
92
  query.limit = 20;
64
93
 
65
94
  [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
95
+ // [query whereKey:@"water" notEqualTo:[NSNull null]];
96
+ // [query whereKey:@"water" notEqualTo:[NSNull null]];
97
+ // [query orderByAscending:@"kaerumsg"];
66
98
  //データストアを検索
67
99
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
68
100
  if (error) {
@@ -73,9 +105,13 @@
73
105
  NSLog(@"検索に成功しました。");
74
106
  //[self.msgs removeAllObjects];
75
107
  for (NCMBObject *object in objects){
108
+ // vals = [object objectForKey:@"kaerumsg"];
109
+ // [self.msgs addObject:vals];
76
- msgs = [object objectForKey:@"kaerumsg"];
110
+ [_msgs addObject:[object objectForKey:@"kaerumsg"]];
111
+ // NSLog(@"%@",vals);
77
- NSLog(@"%@",msgs);
112
+ NSLog(@"%@",_msgs);
78
-
113
+ // [waters addObject:[object objectForKey:@"water"]];
114
+ // NSLog(@"%@",waters);
79
115
  }
80
116
 
81
117
  }
@@ -107,9 +143,11 @@
107
143
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
108
144
 
109
145
  cell.msg.numberOfLines = 0;
146
+ // cell.amountwater.numberOfLines = 0;
110
147
 
111
- cell.msg.text = (NSString*)msgs;
112
- //cell.msg.text = (NSString*)msgs[indexPath.row];
148
+ // cell.msg.text = (NSString*)msgs;
149
+ cell.msg.text = _msgs[indexPath.row];
150
+ // cell.amountwater.text = waters[indexPath.row];
113
151
  return cell;
114
152
  }
115
153
 
@@ -166,7 +204,6 @@
166
204
 
167
205
 
168
206
  ```
169
-
170
207
  ### 試したこと
171
208
 
172
209
  NSLogを用いてデータが検索できているかどうか調べましたが、mBassからの検索はできています。

2

文法の修正とコメントを消してプログラムを見やすくしました。

2018/11/12 14:18

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -16,23 +16,53 @@
16
16
  ### 該当のソースコード
17
17
 
18
18
  ```Objective-C
19
+ #import <Foundation/Foundation.h>
20
+ #import "SecandViewController.h"
21
+ #import "TransitionObj.h"
22
+ #import "givewater.h"
23
+ #import "CustomCell.h"
24
+ #import "NCMB/NCMB.h"
25
+
26
+ @interface SecandViewController ()<UITableViewDataSource, UITableViewDelegate>
27
+ {
28
+
29
+ NSMutableArray *msgs;
30
+ }
31
+
32
+ @end
33
+
34
+ // テーブル表示件数
35
+ //const NSInteger historyNumber = 100;
36
+
37
+ @implementation SecandViewController
38
+
39
+ #pragma mark Life Cycle
40
+
41
+ - (void)viewDidLoad {
42
+ [super viewDidLoad];
43
+ // DelegateとDataSourceはstoryboard(またはxib)のところで結び付けるのでもO.K.
44
+ _tblView.delegate = self;
45
+ _tblView.dataSource = self;
46
+
47
+ // カスタムセルを使用
48
+ UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
49
+ [_tblView registerNib:nib forCellReuseIdentifier:@"Cell"];
50
+
51
+ //保存したデータの検索と取得
52
+ [self setupData];
53
+
54
+ }
55
+
19
56
  //【mBaaS】保存したデータの検索と取得
20
57
 
21
58
  - (void)setupData {
22
59
 
23
60
  // GameScoreクラスを検索するクエリを作成
24
61
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HOGEHOGE"];
25
-
26
- //日付順にデータを取得
27
- // [query addDescendingOrder:@"water"];
28
62
  // 検索件数を設定
29
- //query.limit = historyNumber;
30
- query.limit = 5;
63
+ query.limit = 20;
31
- // [query whereKey:@"date" notEqualTo:[NSNull null]];
64
+
32
- // [query whereKey:@"damileaf" notEqualTo:[NSNull null]];
33
- // [query whereKey:@"hikakuleaf" notEqualTo:[NSNull null]];
34
65
  [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
35
- // [query whereKey:@"water" notEqualTo:[NSNull null]];
36
66
  //データストアを検索
37
67
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
38
68
  if (error) {
@@ -41,37 +71,15 @@
41
71
  } else {
42
72
  // 検索に成功した場合の処理
43
73
  NSLog(@"検索に成功しました。");
74
+ //[self.msgs removeAllObjects];
75
+ for (NCMBObject *object in objects){
76
+ msgs = [object objectForKey:@"kaerumsg"];
77
+ NSLog(@"%@",msgs);
44
78
 
45
- for (NCMBObject *object in objects){
46
- // _dates = [object objectForKey:@"date"];
47
- // _damiTemperatures = [object objectForKey:@"damileaf"];
48
- // _realTemperatures = [object objectForKey:@"hikakuleaf"];
49
- _msgs = [object objectForKey:@"kaerumsg"];
50
- // _amountwaters = [object objectForKey:@"water"];
51
-
52
- //NSLog(@"%@", _dates);
53
- //NSLog(@"%@", _damiTemperatures);
54
- // NSLog(@"%@", _realTemperatures);
55
- // NSLog(@"%@", _msgs);
56
- NSLog(@"%@", _msgs);
57
- //型変換を行う
58
- //NCMBObject *object = objects;
59
-
60
- // [self.dates addObject: object];
61
- // self.dates = [object objectForKey:@"date"];
62
- // self.damiTemperatures = [object objectForKey:@"damileaf"];
63
- // self.realTemperatures = [object objectForKey:@"hikakuleaf"];
64
- // self.msgs = [object objectForKey:@"kaerumsg"];
65
-
66
- // _amountwaters = [object objectForKey:@"water"];
67
- // 取得したデータをプロパティに代入する
68
- //self.dataArray = objects;
69
79
  }
70
-
80
+
71
81
  }
72
82
 
73
- // テーブルビューをリロード
74
- //[self.tblView reloadData];
75
83
  }];
76
84
  // **************************************************
77
85
  //
@@ -86,8 +94,7 @@
86
94
 
87
95
  // セル数
88
96
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
89
- // return [_msgs count];
90
- return 5;
97
+ return 20;
91
98
  }
92
99
 
93
100
 
@@ -98,28 +105,66 @@
98
105
 
99
106
  // カスタムセルを取得
100
107
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
108
+
109
+ cell.msg.numberOfLines = 0;
101
110
 
102
- // cell.date.numberOfLines = 0;
103
- // cell.damiTemperature.numberOfLines = 0;
104
- // cell.realTemperature.numberOfLines = 0;
105
- cell.msg.numberOfLines = 0;
111
+ cell.msg.text = (NSString*)msgs;
106
- // cell.amountwater.numberOfLines = 0;
112
+ //cell.msg.text = (NSString*)msgs[indexPath.row];
113
+ return cell;
114
+ }
115
+
116
+ // セルの高さ設定
117
+ - (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
107
118
 
108
- // イメージビューに背景色をセット
109
- //cell.imgView.image = [UIImage imageNamed:images[indexPath.row]];
119
+ NSLog(@"heightForRowAtIndexPath indexPath:%ld", indexPath.row);
110
- // 各ラベルにテキストをセット
120
+
111
- //NSString *str = [responseDic objectForKey:@"date"]; //文字データが入ると想定されていたが<null>データが格納された
112
- // NSString *firstName=[NSString stringWithFormat:@"%@", [[yourArry objectAtIndex:indexPath.row]valueForKey:@"firstName"]];
113
- // cell.date.text = [NSString stringWithFormat:@"%@",[[_dates objectAtIndex:indexPath.row]valueForKey:@"date"]];
114
- //cell.date.text =[_dates objectAtIndex:indexPath.row];
121
+ //dequeueReusableCellWithIdentifier(セルを使用する)
115
- // cell.damiTemperature.text = [NSString stringWithFormat:@"%@",[[_damiTemperatures objectAtIndex:indexPath.row]valueForKey:@"damiTemperature"]];
116
- cell.msg.text = _msgs[indexPath.row]; //ここでエラーが出ます!!!
117
- // cell.amountwater.text = [_amountwaters objectAtIndex:indexPath.row];
122
+ CustomCell *Cell = [self.tblView dequeueReusableCellWithIdentifier:@"Cell"];
118
- // cell.amountwater.text = _amountwaters[indexPath.row];
119
123
 
124
+ //とりあえず固定値に
125
+ return 200;
126
+ }
127
+
128
+ /**
129
+ * 文字列に必要な高さを計算する処理
130
+ * @param text 文字列
131
+ * @return CGFloat 高さ
132
+ */
133
+ - (CGFloat)calcHeight:(NSString *)text {
120
134
 
135
+ // 端末サイズ取得
136
+ CGRect screen = [[UIScreen mainScreen] bounds];
137
+ // 表示する幅 (40 + 8 * 3):画像の幅(40)とマージンの合計(8*3)
138
+ CGFloat width = screen.size.width - (40 + 8 * 3);
139
+
140
+ // 表示する最大幅と高さ
141
+ CGSize maxSize = CGSizeMake(width, CGFLOAT_MAX);
142
+
143
+ // 文字列のフォント種類、サイズなど属性を指定
144
+ NSDictionary *attrDic = @{NSFontAttributeName:[UIFont systemFontOfSize:15.0]};
145
+
146
+ CGRect rect = [text boundingRectWithSize:maxSize
147
+ options:NSStringDrawingUsesLineFragmentOrigin
148
+ attributes:attrDic
149
+ context:nil];
121
- return cell;
150
+ return rect.size.height;
122
151
  }
152
+
153
+ // セル押下時の処理
154
+ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
155
+
156
+ }
157
+
158
+ #pragma mark Memory
159
+
160
+ - (void)didReceiveMemoryWarning {
161
+ [super didReceiveMemoryWarning];
162
+ // Dispose of any resources that can be recreated.
163
+ }
164
+
165
+ @end
166
+
167
+
123
168
  ```
124
169
 
125
170
  ### 試したこと

1

プログラムを修正しました。

2018/11/12 11:26

投稿

donarudo
donarudo

スコア15

title CHANGED
File without changes
body CHANGED
@@ -4,12 +4,13 @@
4
4
  ちなみ使用しているクラウドはニフクラ mobile backendです。
5
5
  ニフクラドキュメント https://mbaas.nifcloud.com/doc/current/
6
6
  実行してビルドは通るのですが、セルを表示する画面になるとアプリがクラッシュします。
7
+ (11/10プログラム修正しました)
7
8
 
8
9
  ### 発生している問題・エラーメッセージ
9
10
 
10
11
  ```
11
12
  クラッシュする際に表示されるエラーメッセージがこちらです。
12
- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x1148a5890'
13
+ -[__NSCFString objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x114e12a20
13
14
  ```
14
15
 
15
16
  ### 該当のソースコード
@@ -23,10 +24,15 @@
23
24
  NCMBQuery *query = [NCMBQuery queryWithClassName:@"HOGEHOGE"];
24
25
 
25
26
  //日付順にデータを取得
26
- [query addDescendingOrder:@"date"];
27
+ // [query addDescendingOrder:@"water"];
27
28
  // 検索件数を設定
28
29
  //query.limit = historyNumber;
29
-
30
+ query.limit = 5;
31
+ // [query whereKey:@"date" notEqualTo:[NSNull null]];
32
+ // [query whereKey:@"damileaf" notEqualTo:[NSNull null]];
33
+ // [query whereKey:@"hikakuleaf" notEqualTo:[NSNull null]];
34
+ [query whereKey:@"kaerumsg" notEqualTo:[NSNull null]];
35
+ // [query whereKey:@"water" notEqualTo:[NSNull null]];
30
36
  //データストアを検索
31
37
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
32
38
  if (error) {
@@ -35,24 +41,42 @@
35
41
  } else {
36
42
  // 検索に成功した場合の処理
37
43
  NSLog(@"検索に成功しました。");
38
-
44
+
39
- NSArray *hoge = objects;
45
+ for (NCMBObject *object in objects){
46
+ // _dates = [object objectForKey:@"date"];
47
+ // _damiTemperatures = [object objectForKey:@"damileaf"];
48
+ // _realTemperatures = [object objectForKey:@"hikakuleaf"];
49
+ _msgs = [object objectForKey:@"kaerumsg"];
50
+ // _amountwaters = [object objectForKey:@"water"];
51
+
52
+ //NSLog(@"%@", _dates);
53
+ //NSLog(@"%@", _damiTemperatures);
54
+ // NSLog(@"%@", _realTemperatures);
55
+ // NSLog(@"%@", _msgs);
56
+ NSLog(@"%@", _msgs);
40
- //型変換を行う
57
+ //型変換を行う
41
- NCMBObject *object = (NCMBObject*)hoge;
58
+ //NCMBObject *object = objects;
59
+
60
+ // [self.dates addObject: object];
42
- self.dates = [object objectForKey:@"date"];
61
+ // self.dates = [object objectForKey:@"date"];
43
- self.damiTemperatures = [object objectForKey:@"damileaf"];
62
+ // self.damiTemperatures = [object objectForKey:@"damileaf"];
44
- self.realTemperatures = [object objectForKey:@"hikakuleaf"];
63
+ // self.realTemperatures = [object objectForKey:@"hikakuleaf"];
45
- self.msgs = [object objectForKey:@"kaerumsg"];
64
+ // self.msgs = [object objectForKey:@"kaerumsg"];
65
+
46
- self.amountwaters = [object objectForKey:@"water"];
66
+ // _amountwaters = [object objectForKey:@"water"];
47
- // ブルビューード
67
+ // 取得したデパティに代入する
48
- [self.tblView reloadData];
68
+ //self.dataArray = objects;
49
69
  }
70
+
71
+ }
72
+
73
+ // テーブルビューをリロード
74
+ //[self.tblView reloadData];
50
75
  }];
51
76
  // **************************************************
52
- //
77
+ //
53
78
  }
54
79
 
55
-
56
80
  #pragma mark UITableView
57
81
 
58
82
  // セクション数
@@ -62,8 +86,8 @@
62
86
 
63
87
  // セル数
64
88
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
65
- return [_dates count];
66
- //return 100;
89
+ // return [_msgs count];
90
+ return 5;
67
91
  }
68
92
 
69
93
 
@@ -75,30 +99,33 @@
75
99
  // カスタムセルを取得
76
100
  CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
77
101
 
78
- cell.date.numberOfLines = 0;
102
+ // cell.date.numberOfLines = 0;
79
- cell.damiTemperature.numberOfLines = 0;
103
+ // cell.damiTemperature.numberOfLines = 0;
80
- cell.realTemperature.numberOfLines = 0;
104
+ // cell.realTemperature.numberOfLines = 0;
81
- cell.msg.numberOfLines = 0;
105
+ cell.msg.numberOfLines = 0;
82
- cell.amountwater.numberOfLines = 0;
106
+ // cell.amountwater.numberOfLines = 0;
83
107
 
84
108
  // イメージビューに背景色をセット
85
109
  //cell.imgView.image = [UIImage imageNamed:images[indexPath.row]];
86
110
  // 各ラベルにテキストをセット
111
+ //NSString *str = [responseDic objectForKey:@"date"]; //文字データが入ると想定されていたが<null>データが格納された
112
+ // NSString *firstName=[NSString stringWithFormat:@"%@", [[yourArry objectAtIndex:indexPath.row]valueForKey:@"firstName"]];
113
+ // cell.date.text = [NSString stringWithFormat:@"%@",[[_dates objectAtIndex:indexPath.row]valueForKey:@"date"]];
87
- cell.date.text = self.dates[indexPath.row];
114
+ //cell.date.text =[_dates objectAtIndex:indexPath.row];
88
- cell.damiTemperature.text = self.damiTemperatures[indexPath.row];
115
+ // cell.damiTemperature.text = [NSString stringWithFormat:@"%@",[[_damiTemperatures objectAtIndex:indexPath.row]valueForKey:@"damiTemperature"]];
89
- cell.realTemperature.text = self.realTemperatures[indexPath.row];
90
- cell.msg.text = self.msgs[indexPath.row];
116
+ cell.msg.text = _msgs[indexPath.row]; //ここでエラーが出ます!!!
117
+ // cell.amountwater.text = [_amountwaters objectAtIndex:indexPath.row];
91
- cell.amountwater.text = self.amountwaters[indexPath.row];
118
+ // cell.amountwater.text = _amountwaters[indexPath.row];
119
+
92
120
 
93
121
  return cell;
94
122
  }
95
-
96
123
  ```
97
124
 
98
125
  ### 試したこと
99
126
 
100
127
  NSLogを用いてデータが検索できているかどうか調べましたが、mBassからの検索はできています。
101
- おそらくデータを配列に入れるところで間違っていると思いますので、どなたかご指摘よろしくお願いします。
128
+ おそらくデータを配列に入れてテキストに表示させるところで間違っていると思いますので、どなたかご指摘よろしくお願いします。
102
129
 
103
130
  ### 補足情報(FW/ツールのバージョンなど)
104
131
  iOS11.4