從頭開始使用TVC和核心數據表視圖控制器。 我已經在viewdidload中實現了一次刷新。事情是,當我使用例如sqllite更新核心數據,數據不更新,即使我打電話[self.tableView reloadData];
表視圖控制器不顯示更新的核心數據值
我MasterViewController.h:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface MasterViewController : UITableViewController <NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@end
和我MasterViewController.m(蘋果模板) :
#import "MasterViewController.h"
@interface MasterViewController()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation MasterViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
// Initialize Refresh Control
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
// Configure Refresh Control
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
// Configure View Controller
[self setRefreshControl:refreshControl];
}
- (void)refresh:(id)sender {
NSLog(@"Refreshing View ...");
// End Refreshing
[(UIRefreshControl *)sender endRefreshing];
[self.tableView reloadData];
}
感謝您的幫助!
是否行 NSLog(@「Refreshing View ...」); 被叫?如果是這樣,我認爲我們需要您的cellForRowAtIndexPathMethod來提供答案。 – JWKothe
被稱爲YE。忘了在刷新程序中添加一個提取器! – kesdonc