我有一個可用視圖,每5秒運行一次方法獲取列表。當該記錄的核心數據中有更新的數據時,提取列表方法不會將最新數據更新到其數組中。因此,當我重新載入數據時,它總是顯示「舊」記錄。UItableview不刷新來自核心數據的更新數據
我打電話給這個方法,然後在uitableview上重新載入數據。
這是我獲取列表的方法:
- (void) fetchList:(int) listNo{
// Define our table/entity to use
self.marketWatchListArray = nil;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Market_watch" inManagedObjectContext:context];
// Setup the fetch request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
Mobile_TradingAppDelegate *appDelegate = (Mobile_TradingAppDelegate *)[[UIApplication sharedApplication] delegate];
NSPredicate *getList = [NSPredicate predicateWithFormat:@"(list_id == %d) AND (userID == %@)", listNo, appDelegate.user_number];
[request setPredicate:getList];
NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"stockName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortByName]];
// Fetch the records and handle an error
NSError *error;
NSMutableArray *mutableFetchResults = [[context executeFetchRequest:request error:&error] mutableCopy];
if (!mutableFetchResults) {
// Handle the error.
// This is a serious error and should advise the user to restart the application
}
// Save our fetched data to an array
[self setMarketWatchListArray: mutableFetchResults];
[mutableFetchResults release];
[request release];
}
奇怪的是表當定時器運行fetchlist不與最新更新:1。當我切換到fetchlist:2時,然後回到fetchlist:1,表格被更新爲最新的。
我有一個segmentcontrol切換不同的列表。
是這樣做了!它不工作! – kraitz 2012-01-27 03:49:59
當我在fetchlist方法中打印對象中的數據時,它讀取的數組中的數據已經包含過時的數據。 – kraitz 2012-01-27 04:04:15
我做到了!帶上下文的refreshObject方法。 謝謝! – kraitz 2012-01-27 07:23:50