【发布时间】:2012-01-27 03:40:18
【问题描述】:
我有一个带有每 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 时,表会更新为最新的。
我有一个段控件可以在不同的列表之间切换。
【问题讨论】:
标签: objective-c ios cocoa-touch core-data