2014-03-05 27 views
2

我遇到了什麼,我相信這是一個缺陷,但我不知道這是否是在我的代碼,或在RubyMotion,或在iOS的...NSFetchedResultsController創建,但部分是零

「標籤」的模式:我的控制器的viewDidLoad方法的

class Tag < CDQManagedObject 
    def sectionIdentifier 
    puts "Called" 
    name ? name[0] : " " 
    end 

    def keyPathsForValuesAffectingSectionIdentifier 
    NSSet.setWithObject("name") 
    end 
end 

部分:

self.query = Tag.sort_by(:name) 
self.tags_results = NSFetchedResultsController.alloc.initWithFetchRequest(self.query.fetch_request, managedObjectContext: cdq.contexts.current, sectionNameKeyPath: "sectionIdentifier", cacheName: nil) 
self.tags_results.delegate = self 
puts tags_results.sections.inspect 

的問題是,tags_results.sections爲零。我在這裏有什麼問題,但我不知道在哪裏。

回答

3

嗯......

我以前從來沒有這樣不是100%確定使用rubymotion。

但是,如果這是你使用的所有代碼,那麼我認爲我看到了問題。

NSFetchedResultsController創建你給它的要求,sectionIdentifier等..

但是,你不告訴控制器實際運行抓取。

Objective-C我會做...

[fetchedResultsController performFetch:nil]; 

這告訴控制器去實際得到的結果。

只有在部分屬性填充。

sections屬性是一個實際獲取對象的數組,因此不需要讀取它們就永遠是零。

編輯

是...

從文檔... http://www.rubymotion.com/developer-center/api/NSFetchedResultsController.html#performFetch%3A-instance_method

你需要運行......

self.tags_results.performFetch(nil) 
// or whatever the syntax is 
+0

非常感謝你。這正是問題。 –

+0

樂意提供幫助。真高興你做到了。 – Fogmeister

相關問題