我有一個多線程應用程序,我有一個問題,我可以在UIViewController中打開一個項目進行更改,但另一個線程中的數據已經可以更改,並且當我單擊提交按鈕 - 我重寫了另一個線程所做的更改。 (例如,物品的數量發生了變化 - 有人在管理員更改倉庫中物品的數量時購買了物品)。數據在UIViewController編輯過程中發生了變化
所以現在我有一個可編輯的項目,並作出這樣的變化一個UIViewController:
- (IBAction)submitButton:(id)sender
{
NSDictionary *changedData = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:nameField.text, priceField.text, quantityField.text, _itemUUID, nil]
forKeys:[NSArray arrayWithObjects: @"Name", @"Price", @"Quantity", @"UUID", nil]];
[[EADataManager sharedInstance] updateItemWithData:changedData atUUID:_itemUUID];
[self.navigationController popViewControllerAnimated:YES];
}
,並在我的DataManager類的數據更新方法:
- (void) updateItemWithData:(NSDictionary *)data atUUID:(NSString*)UUID
{
[self networkActivityIndicatorVisible:YES];
dispatch_barrier_async(_dataManagerQueue, ^{
[NSThread sleepForTimeInterval:5.0];
NSInteger path = [self indexFromObjectUUID:UUID];
if (path != NSNotFound)
{
[_items replaceObjectAtIndex:path withObject:data];
[_dataStorageAdapter saveFileWithData:_items];
} else {
[_items addObject:data];
[_dataStorageAdapter saveFileWithData:_items];
}
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:EADataManagerUpdateViews
object:nil];
});
[self networkActivityIndicatorVisible:NO];
});
}
所以項目可能編輯從不同的線程或其他方法,我不知道如何使這項工作很好。我相信代表團對此非常好,但我不能在這裏實施,有什麼想法?