私はいくつかのTabBarControllersを持つTabBarで構成されるアプリケーションを持っています。 1つのコントローラには非常に単純なテーブルがあり、NSMutableDictionaryの内容を表示することになっています。適切なボタンを押すと、辞書は別のコントローラで更新され、ビューはUITableViewController
に切り替わり、新しく更新されたテーブルが表示されます。UITableViewは更新されません
辞書が更新されているのがわかります。しかし、TableViewは変更を反映しません。実際、私はその画面に初めて入るときだけ変更を表示するようです。
私は[self table.reloadData]を試していますが、呼び出されても変更内容はUITableView
に反映されません。
誰にも提案はありますか?私はコードを投稿してうれしく思いますが、何を投稿すればよいかわかりません。
更新:テーブルは、最初に表示されたときにのみ更新され、適切に更新されます。後続のディスプレイには、元の内容が表示されます。
背景: テーブルビューは、辞書:appDelegate.currentFaveから入力されます。 ViewControllerがTabBarControllerによって呼び出されるたびに、テーブルビューが更新されます。あなたが我慢しているコードが正しいと仮定
は- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"in viewWillAppear");
[super viewWillAppear:animated];
[self loadFavesFile];
[self.tableView reloadData];
}
// load the Favorites file from disk
- (void) loadFavesFile
{
// get location of file
NSString *path = [self getFavesFilePath];
// The Favorites .plist data is different from the Affirmations in that it will never be stored in the bundle. Instead,
// if it exists, then use it. If not, no problem.
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
// read Faves file and store it for later use...
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithContentsOfFile:path];
appDelegate.sharedData.dictFaves = tempDict;
// grab the latest quote. Append it to the list of existing favorites
NSString *key = [NSString stringWithFormat:@"%d", appDelegate.sharedData.dictFaves.count + 1];
NSString *newFave = [NSString stringWithFormat:@"%@", appDelegate.currentFave];
[appDelegate.sharedData.dictFaves setObject:newFave forKey:key];
} else {
NSLog(@"Favorites file doesn't exist");
appDelegate.sharedData.dictFaves = nil;
}
}
// this gets invoked the very first call. Only once per running of the App.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// reuse or create the cell
static NSString *cellID = @"cellId";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
// allow longer lines to wrap
cell.textLabel.numberOfLines = 0; // Multiline
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.font = [UIFont fontWithName:@"Chalkduster" size:(16)];
cell.textLabel.textColor = [UIColor yellowColor];
// NOTE: for reasons unknown, I cannot set either the cell- or table- background color. So it must be done using the Label.
// set the text for the cell
NSString *row = [NSString stringWithFormat:@"%d", indexPath.row + 1];
cell.textLabel.text = [appDelegate.sharedData.dictFaves objectForKey:row];
return cell;
}
私の一部の誤字。謝罪。 – Bassman
これはコメントであり、回答ではありません –