ios - How do I use FetchedResultsController if I have two different kinds of cells? -


i have prototype tableview in ib, has 2 different kinds of cells: complete cell, , basic cell (for displaying articles, use each 1 depending kind of article is).

i want integrate fetchedresultscontroller app can use coredata populate tableview, (using nsarray instead of fetchedresultscontroller) handled cell setup follows:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     int row = indexpath.row;     static nsstring *cellidentifier = nil;     article *article = self.articles[row];      // checks if user added body of text (not source or url)     if (article.isuseraddedtext) {         cellidentifier = @"basicarticlecell";     }     else {         cellidentifier = @"fullarticlecell";     }      articlecell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath];      // if user added body of text, articlepreview , progress has set     cell.articlepreview.text = article.preview;     cell.articleprogress.text = [self calculatetimeleft:article];      // if it's url or source, set title , url     if (!article.isuseraddedtext) {         cell.articletitle.text = article.title;         cell.articleurl.text = article.url;     }      return cell; } 

but don't know how check whether or not basic article or not (as before checked property of article object in nsarray). 1 article saw did this:

- (uitableviewcell *)tableview:(uitableview *)tableview     cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"cell";      uitableviewcell *cell =         [tableview dequeuereusablecellwithidentifier:cellidentifier];      // set cell...     [self configurecell:cell atindexpath:indexpath];      return cell; } 

but need know kind of article before decide cell identifier is, don't see how here. able fetchedresultcontroller object early, query see value of article property (whether or not it's basic) , set cellidentifier accordingly? or there else should doing?

tl;dr: how decide cellidentifier depending on kind of object shown in cell when using fetchedresultscontroller.

you can use exact same logic doing before retrieval of article looks little different

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {   article *article = [self.fetchedresultscontroller objectatindexpath:indexpath];    nsstring *cellidentifier = [article isuseraddedtext] ? @"basicarticlecell" : @"fullarticlecell";    uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];    // set cell...   [self configurecell:cell atindexpath:indexpath];    return cell; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -