[英]After retrieving data from Firebase, how to send retrieved data from one view controller to another view controller?
[英]How to get fetchedResultsController to feed my TableView, based on an object that was retrieved from another FRC in a previous view controller?
這是我的結構:
我有一個稱為元素的實體。 元素包含多個時間戳。 時間戳是與元素有關系的實體。
Element
Time Stamp 1
Time Stamp 2
Time Stamp 3,
...,
...
我的視圖控制器和表視圖是:
View Controller A
TableView A // <- displays elements
View Controller B
TableView B // <- should display all timestamps from a given element
我正在嘗試做的是:
我可以在View Controller A中獲取“元素”,並將其傳遞給View Controller B,如下所示:
Element *anElement = [_fetchedResultsController objectAtIndexPath:indexPath];
ViewControllerB *vc = (ViewControllerB *)[[self storyboard]instantiateViewControllerWithIdentifier:@"ViewControllerB"];
vc.element = anElement;
現在,在我的View Controller BI上有一個fetchedResultsController,它可以為Table View B提供數據。我需要這個fetchedResultsController顯示傳遞的Element對象中的所有時間戳。
我怎樣才能做到這一點?
我知道我可以通過向Element添加一個唯一的date屬性來解決此問題,以便在View Controller B中可以有一個與該唯一的日期匹配的謂詞。 但是,如果可能的話,我寧願不這樣做。 我發現很難相信我需要擁有核心數據實體來依賴我在View Controller中需要執行的操作。
謝謝!
您應該能夠將以下謂詞與fetchedResultsController一起使用以獲取TimeStamp對象。
[NSPredicate predicateWithFormat:@"element == %@", self.element];
如果時間戳記是NSSet,則可以將其傳遞給ViewController B並取消使用B中的fetchedResultsController。
或者,而不是像上面那樣分配實體,將NSManagedObjectID傳遞給ViewController B並在此基礎上進行提取。 如果要在B中使用提取控制器,這將是更好的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.