簡體   English   中英

UItableview不刷新核心數據的更新數據

[英]UItableview not refreshing updated data from core data

我有一個uitableview,每5秒運行一次方法獲取列表。 當該記錄的核心數據中存在更新數據時,獲取列表方法不會將最新數據更新到其數組中。 因此,當我重新加載數據時,它總是顯示“舊”記錄。

我調用此方法,然后在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來切換不同的列表。

在獲取之前添加此行:

 [context setStalenessInterval: 4.0]; // allow objects to be stale for max of 4 seconds

在fetchList方法的末尾,添加以下代碼以刷新UITableView中的數據:

[yourTableView reloadData];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM