質問編集履歴
2
ソースコードを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
*追記
|
13
13
|
|
14
|
-
下記がUITableViewを更新しようとしていコードになります。
|
14
|
+
下記がUITableViewを更新しようとしているコードになります。
|
15
15
|
|
16
16
|
```objective-c
|
17
17
|
|
@@ -26,25 +26,97 @@
|
|
26
26
|
hoge.mの中
|
27
27
|
|
28
28
|
int iUserCnt;
|
29
|
+
CGRect listView_windowsize;
|
30
|
+
float listView_height_windowsize;
|
31
|
+
float listView_width_windowsize;
|
29
32
|
|
33
|
+
- (void)viewDidLoad { //tableviewの生成
|
34
|
+
|
35
|
+
listView_windowsize = [[UIScreen mainScreen] bounds];
|
36
|
+
listView_height_windowsize = listView_windowsize.size.height;
|
37
|
+
listView_width_windowsize = listView_windowsize.size.width;
|
38
|
+
|
39
|
+
listtable = [[UITableView alloc] initWithFrame:[self.view bounds]];
|
40
|
+
listtable.frame = CGRectMake(0, 44 , listView_width_windowsize, listView_height_windowsize * 0.8);
|
41
|
+
listtable.delegate = self;
|
42
|
+
listtable.dataSource = self;
|
43
|
+
listtable.allowsMultipleSelection = YES;
|
44
|
+
[self.view addSubview:listtable];
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
- (void)OnEnterMember:(const char*)strUserId { //サーバーから通知を受け取る関数(ここも都合上、割愛させてもらってます)
|
49
|
+
|
50
|
+
[self performSelectorOnMainThread:@selector(DisplayList) withObject:nil waitUntilDone:YES];
|
51
|
+
|
52
|
+
}
|
53
|
+
|
54
|
+
-(void)get_data{ //サーバーからxml形式でデータを取得し、格納する。(サーバと通信してる部分等は省略してます)
|
55
|
+
|
56
|
+
m_UserListDict = [[NSMutableDictionary alloc]init];
|
57
|
+
[m_UserListDict setDictionary:UserList];
|
58
|
+
for (id key in m_UserListDict){
|
59
|
+
NSLog(@"%@,%@", key, m_UserListDict[key]);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //セクションの数を返す
|
64
|
+
{
|
65
|
+
// Return the number of sections.
|
66
|
+
return 1;
|
67
|
+
}
|
68
|
+
|
69
|
+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //cellの数を返す
|
70
|
+
{
|
71
|
+
|
72
|
+
return self.hoge.count;
|
73
|
+
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
78
|
+
UITableViewCell *cell;
|
79
|
+
|
80
|
+
static NSString *CellIdentifier = @"Cell";
|
81
|
+
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
82
|
+
|
83
|
+
if (cell == nil) {
|
84
|
+
|
85
|
+
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
|
86
|
+
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
87
|
+
|
88
|
+
}
|
89
|
+
cell.textLabel.text = [self.hoge objectAtIndex:indexPath.row];
|
90
|
+
|
91
|
+
return cell;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
30
95
|
-(void)DisplayList{
|
96
|
+
|
31
|
-
|
97
|
+
[self get_data];
|
98
|
+
|
99
|
+
NSLog(@"isMainThread=%@", NSThread.currentThread.isMainThread?@"YES":@"NO");
|
32
100
|
str = [[NSString alloc]init];
|
33
101
|
val = [[NSMutableArray alloc]init];
|
34
|
-
self.
|
102
|
+
self.userlistarray = [[NSMutableArray alloc]init];
|
103
|
+
UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
|
104
|
+
iUserCnt = [UserCnt intValue];
|
35
105
|
|
36
|
-
UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
|
37
|
-
iUserCnt = [UserCnt intValue];
|
38
|
-
|
39
106
|
for ( int i = 0; i < iUserCnt; i++){
|
40
|
-
|
107
|
+
|
41
108
|
str = [NSString stringWithFormat:@"%d", i];
|
42
109
|
val = [[m_UserListDict objectForKey:str] objectForKey:@"name"];
|
43
110
|
[self.hoge addObject:val];
|
44
111
|
|
45
|
-
|
112
|
+
}
|
113
|
+
NSLog(@"reloadDataの直前のlisttable=%@", listtable);
|
114
|
+
|
46
115
|
[listtable reloadData];
|
116
|
+
|
117
|
+
NSLog(@"reloadDataの直後のlisttable=%@", listtable);
|
118
|
+
userlistcnt = (int)[self.userlistarray count];
|
47
|
-
|
119
|
+
}
|
48
120
|
```
|
49
121
|
処理の流れとしてはm_UserListDictの中にあるnameというkeyで保存されている値をvalに入れてそれを
|
50
122
|
self.hogeに入れて最後に[listtable reloadData];を行っている処理になります。
|
1
ソースコードの追記をしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,48 @@
|
|
6
6
|
|
7
7
|
この原因がわかる方おりましたら教えていただけると幸いです。
|
8
8
|
以上です。
|
9
|
+
よろしくお願いいたします。
|
10
|
+
|
11
|
+
|
12
|
+
*追記
|
13
|
+
|
14
|
+
下記がUITableViewを更新しようとしていコードになります。
|
15
|
+
|
16
|
+
```objective-c
|
17
|
+
|
18
|
+
hoge.hの中
|
19
|
+
|
20
|
+
NSMutableDictionary *m_UserListDict;
|
21
|
+
@property (retain, nonatomic)NSMutableArray *hoge;
|
22
|
+
NSString *UserCnt;
|
23
|
+
NSString *str;
|
24
|
+
NSMutableArray *val;
|
25
|
+
|
26
|
+
hoge.mの中
|
27
|
+
|
28
|
+
int iUserCnt;
|
29
|
+
|
30
|
+
-(void)DisplayList{
|
31
|
+
|
32
|
+
str = [[NSString alloc]init];
|
33
|
+
val = [[NSMutableArray alloc]init];
|
34
|
+
self.hoge = [[NSMutableArray alloc]init];
|
35
|
+
|
36
|
+
UserCnt = [m_UserListDict objectForKey:@"UserCnt"];
|
37
|
+
iUserCnt = [UserCnt intValue];
|
38
|
+
|
39
|
+
for ( int i = 0; i < iUserCnt; i++){
|
40
|
+
|
41
|
+
str = [NSString stringWithFormat:@"%d", i];
|
42
|
+
val = [[m_UserListDict objectForKey:str] objectForKey:@"name"];
|
43
|
+
[self.hoge addObject:val];
|
44
|
+
|
45
|
+
|
46
|
+
[listtable reloadData];
|
47
|
+
}
|
48
|
+
```
|
49
|
+
処理の流れとしてはm_UserListDictの中にあるnameというkeyで保存されている値をvalに入れてそれを
|
50
|
+
self.hogeに入れて最後に[listtable reloadData];を行っている処理になります。
|
51
|
+
m_UserListDictの中身が空とかいう問題はありませんでした。
|
52
|
+
|
9
53
|
よろしくお願いいたします。
|