質問編集履歴

2

ソースコードを追記しました。

2015/12/11 06:45

投稿

mm--_--mm
mm--_--mm

スコア113

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- 下記がUITableViewを更新しようとしていコードになります。
27
+ 下記がUITableViewを更新しようとしていコードになります。
28
28
 
29
29
 
30
30
 
@@ -54,43 +54,187 @@
54
54
 
55
55
  int iUserCnt;
56
56
 
57
+ CGRect listView_windowsize;
58
+
59
+ float listView_height_windowsize;
60
+
61
+ float listView_width_windowsize;
62
+
63
+
64
+
65
+ - (void)viewDidLoad { //tableviewの生成
66
+
67
+
68
+
69
+ listView_windowsize = [[UIScreen mainScreen] bounds];
70
+
71
+ listView_height_windowsize = listView_windowsize.size.height;
72
+
73
+ listView_width_windowsize = listView_windowsize.size.width;
74
+
75
+
76
+
77
+ listtable = [[UITableView alloc] initWithFrame:[self.view bounds]];
78
+
79
+ listtable.frame = CGRectMake(0, 44 , listView_width_windowsize, listView_height_windowsize * 0.8);
80
+
81
+ listtable.delegate = self;
82
+
83
+ listtable.dataSource = self;
84
+
85
+ listtable.allowsMultipleSelection = YES;
86
+
87
+ [self.view addSubview:listtable];
88
+
89
+
90
+
91
+ }
92
+
93
+
94
+
95
+ - (void)OnEnterMember:(const char*)strUserId { //サーバーから通知を受け取る関数(ここも都合上、割愛させてもらってます)
96
+
97
+
98
+
99
+ [self performSelectorOnMainThread:@selector(DisplayList) withObject:nil waitUntilDone:YES];
100
+
101
+
102
+
103
+ }
104
+
105
+
106
+
107
+ -(void)get_data{ //サーバーからxml形式でデータを取得し、格納する。(サーバと通信してる部分等は省略してます)
108
+
109
+
110
+
111
+ m_UserListDict = [[NSMutableDictionary alloc]init];
112
+
113
+ [m_UserListDict setDictionary:UserList];
114
+
115
+ for (id key in m_UserListDict){
116
+
117
+ NSLog(@"%@,%@", key, m_UserListDict[key]);
118
+
119
+ }
120
+
121
+ }
122
+
123
+
124
+
125
+ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //セクションの数を返す
126
+
127
+ {
128
+
129
+ // Return the number of sections.
130
+
131
+ return 1;
132
+
133
+ }
134
+
135
+
136
+
137
+ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //cellの数を返す
138
+
139
+ {
140
+
141
+
142
+
143
+ return self.hoge.count;
144
+
145
+
146
+
147
+
148
+
149
+ }
150
+
151
+
152
+
153
+ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
154
+
155
+ UITableViewCell *cell;
156
+
157
+
158
+
159
+ static NSString *CellIdentifier = @"Cell";
160
+
161
+ cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
162
+
163
+
164
+
165
+ if (cell == nil) {
166
+
167
+
168
+
169
+ cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
170
+
171
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
172
+
173
+
174
+
175
+ }
176
+
177
+ cell.textLabel.text = [self.hoge objectAtIndex:indexPath.row];
178
+
179
+
180
+
181
+ return cell;
182
+
183
+
184
+
185
+ }
186
+
57
187
 
58
188
 
59
189
  -(void)DisplayList{
60
190
 
191
+
192
+
61
-
193
+ [self get_data];
194
+
195
+
196
+
197
+ NSLog(@"isMainThread=%@", NSThread.currentThread.isMainThread?@"YES":@"NO");
62
198
 
63
199
  str = [[NSString alloc]init];
64
200
 
65
201
  val = [[NSMutableArray alloc]init];
66
202
 
67
- self.hoge = [[NSMutableArray alloc]init];
203
+ self.userlistarray = [[NSMutableArray alloc]init];
68
-
69
-
70
-
204
+
71
- UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
205
+ UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
72
-
206
+
73
- iUserCnt = [UserCnt intValue];
207
+ iUserCnt = [UserCnt intValue];
74
208
 
75
209
 
76
210
 
77
211
  for ( int i = 0; i < iUserCnt; i++){
78
212
 
213
+
214
+
215
+ str = [NSString stringWithFormat:@"%d", i];
216
+
217
+ val = [[m_UserListDict objectForKey:str] objectForKey:@"name"];
218
+
219
+ [self.hoge addObject:val];
220
+
79
221
 
80
222
 
223
+ }
224
+
81
- str = [NSString stringWithFormat:@"%d", i];
225
+ NSLog(@"reloadDataの直前のlisttable=%@", listtable);
82
-
83
- val = [[m_UserListDict objectForKey:str] objectForKey:@"name"];
226
+
84
-
85
- [self.hoge addObject:val];
227
+
86
-
87
-
88
-
89
-
90
228
 
91
229
  [listtable reloadData];
92
230
 
231
+
232
+
233
+ NSLog(@"reloadDataの直後のlisttable=%@", listtable);
234
+
235
+ userlistcnt = (int)[self.userlistarray count];
236
+
93
- }
237
+ }
94
238
 
95
239
  ```
96
240
 

1

ソースコードの追記をしました。

2015/12/11 06:45

投稿

mm--_--mm
mm--_--mm

スコア113

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,91 @@
15
15
  以上です。
16
16
 
17
17
  よろしくお願いいたします。
18
+
19
+
20
+
21
+
22
+
23
+ *追記
24
+
25
+
26
+
27
+ 下記がUITableViewを更新しようとしていコードになります。
28
+
29
+
30
+
31
+ ```objective-c
32
+
33
+
34
+
35
+ hoge.hの中
36
+
37
+
38
+
39
+ NSMutableDictionary *m_UserListDict;
40
+
41
+ @property (retain, nonatomic)NSMutableArray *hoge;
42
+
43
+ NSString *UserCnt;
44
+
45
+ NSString *str;
46
+
47
+ NSMutableArray *val;
48
+
49
+
50
+
51
+ hoge.mの中
52
+
53
+
54
+
55
+ int iUserCnt;
56
+
57
+
58
+
59
+ -(void)DisplayList{
60
+
61
+
62
+
63
+ str = [[NSString alloc]init];
64
+
65
+ val = [[NSMutableArray alloc]init];
66
+
67
+ self.hoge = [[NSMutableArray alloc]init];
68
+
69
+
70
+
71
+ UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
72
+
73
+ iUserCnt = [UserCnt intValue];
74
+
75
+
76
+
77
+ for ( int i = 0; i < iUserCnt; i++){
78
+
79
+
80
+
81
+ str = [NSString stringWithFormat:@"%d", i];
82
+
83
+ val = [[m_UserListDict objectForKey:str] objectForKey:@"name"];
84
+
85
+ [self.hoge addObject:val];
86
+
87
+
88
+
89
+
90
+
91
+ [listtable reloadData];
92
+
93
+ }
94
+
95
+ ```
96
+
97
+ 処理の流れとしてはm_UserListDictの中にあるnameというkeyで保存されている値をvalに入れてそれを
98
+
99
+ self.hogeに入れて最後に[listtable reloadData];を行っている処理になります。
100
+
101
+ m_UserListDictの中身が空とかいう問題はありませんでした。
102
+
103
+
104
+
105
+ よろしくお願いいたします。