いつもお世話になっております。
表題の件ですが、一回UITableViewをviewdidlaod内で生成し、値を表示した後に別の関数でもう一度cellに表示する値を取得しなおして一回目に生成したUITableViewを削除し、もう一回UITableViewを生成したいのですが、2回目以降からUITableViewを作成しようとしてもcellForRowAtIndexPathが呼ばれず、作成することができません...
調べてみると、numberOfRowsInSectionの値は0になっているとcellForRowAtIndexPathが呼ばれないとネットに書いてありましたが、NSLogで確認してみたところ、0にはなっていませんでした。
この原因がわかる方おりましたら教えていただけると幸いです。
以上です。
よろしくお願いいたします。
*追記
下記がUITableViewを更新しようとしているコードになります。
objective
1 2hoge.hの中 3 4NSMutableDictionary *m_UserListDict; 5@property (retain, nonatomic)NSMutableArray *hoge; 6NSString *UserCnt; 7NSString *str; 8NSMutableArray *val; 9 10hoge.mの中 11 12int iUserCnt; 13CGRect listView_windowsize; 14float listView_height_windowsize; 15float listView_width_windowsize; 16 17- (void)viewDidLoad { //tableviewの生成 18 19 listView_windowsize = [[UIScreen mainScreen] bounds]; 20 listView_height_windowsize = listView_windowsize.size.height; 21 listView_width_windowsize = listView_windowsize.size.width; 22 23 listtable = [[UITableView alloc] initWithFrame:[self.view bounds]]; 24 listtable.frame = CGRectMake(0, 44 , listView_width_windowsize, listView_height_windowsize * 0.8); 25 listtable.delegate = self; 26 listtable.dataSource = self; 27 listtable.allowsMultipleSelection = YES; 28 [self.view addSubview:listtable]; 29 30} 31 32- (void)OnEnterMember:(const char*)strUserId { //サーバーから通知を受け取る関数(ここも都合上、割愛させてもらってます) 33 34 [self performSelectorOnMainThread:@selector(DisplayList) withObject:nil waitUntilDone:YES]; 35 36} 37 38-(void)get_data{ //サーバーからxml形式でデータを取得し、格納する。(サーバと通信してる部分等は省略してます) 39 40 m_UserListDict = [[NSMutableDictionary alloc]init]; 41 [m_UserListDict setDictionary:UserList]; 42 for (id key in m_UserListDict){ 43 NSLog(@"%@,%@", key, m_UserListDict[key]); 44 } 45} 46 47- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //セクションの数を返す 48{ 49 // Return the number of sections. 50 return 1; 51} 52 53- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //cellの数を返す 54{ 55 56 return self.hoge.count; 57 58 59} 60 61- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 62 UITableViewCell *cell; 63 64 static NSString *CellIdentifier = @"Cell"; 65 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 66 67 if (cell == nil) { 68 69 cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 70 cell.selectionStyle = UITableViewCellSelectionStyleNone; 71 72 } 73 cell.textLabel.text = [self.hoge objectAtIndex:indexPath.row]; 74 75 return cell; 76 77} 78 79-(void)DisplayList{ 80 81 [self get_data]; 82 83 NSLog(@"isMainThread=%@", NSThread.currentThread.isMainThread?@"YES":@"NO"); 84 str = [[NSString alloc]init]; 85 val = [[NSMutableArray alloc]init]; 86 self.userlistarray = [[NSMutableArray alloc]init]; 87 UserCnt = [m_UserListDict objectForKey:@"UserCnt"]; 88 iUserCnt = [UserCnt intValue]; 89 90 for ( int i = 0; i < iUserCnt; i++){ 91 92 str = [NSString stringWithFormat:@"%d", i]; 93 val = [[m_UserListDict objectForKey:str] objectForKey:@"name"]; 94 [self.hoge addObject:val]; 95 96 } 97 NSLog(@"reloadDataの直前のlisttable=%@", listtable); 98 99 [listtable reloadData]; 100 101 NSLog(@"reloadDataの直後のlisttable=%@", listtable); 102 userlistcnt = (int)[self.userlistarray count]; 103}
処理の流れとしてはm_UserListDictの中にあるnameというkeyで保存されている値をvalに入れてそれを
self.hogeに入れて最後に[listtable reloadData];を行っている処理になります。
m_UserListDictの中身が空とかいう問題はありませんでした。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/09 07:42
2015/12/09 07:55 編集
2015/12/09 07:58
2015/12/09 08:01
2015/12/09 08:03
2015/12/09 08:07
2015/12/09 08:14
2015/12/09 08:30
2015/12/09 08:39 編集
2015/12/09 09:24
2015/12/09 12:04 編集
2015/12/09 10:01
2015/12/09 15:30 編集
2015/12/10 00:18
2015/12/10 00:19
2015/12/10 00:31
2015/12/10 00:42
2015/12/10 01:03
2015/12/10 01:15
2015/12/10 01:48
2015/12/10 01:50
2015/12/10 05:04
2015/12/10 05:43
2015/12/10 06:00
2015/12/10 06:14 編集
2015/12/10 06:19
2015/12/10 06:47
2015/12/10 08:31
2015/12/10 09:02 編集
2015/12/10 09:17
2015/12/10 09:25
2015/12/10 09:33
2015/12/10 09:40
2015/12/10 09:46
2015/12/11 05:08
2015/12/11 05:56
2015/12/11 06:05
2015/12/11 06:45
2015/12/11 07:38
2015/12/11 07:47
2015/12/11 08:02
2015/12/11 08:05
2015/12/11 08:30
2015/12/11 08:43
2015/12/11 08:50
2015/12/11 08:57
2015/12/11 09:06