iphone - How do I utilize CoreData when moving from collection view to detail view -


i have ios app using restkit pull json formatted data server coredata entity. of attributes of entity populate collection view image , title each cell.

i attempting move collection view detail view when cell selected. there "summary" attribute of coredata entity display in detail view along image.

i know can pass data thru prepareforsegue method. i not sure how specify image , summary data want pass.

maybe passing image , summary not proper way? should passing managedobjectcontext detail view controller , fetching results there?

here how collectionview populated.

- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {  static nsstring *cellidentifier = @"cell";  mynewscollectionviewcell *cell = (mynewscollectionviewcell *)[collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; nsmanagedobject *object = [self.fetchedresultscontroller objectatindexpath:indexpath]; nsurl *photourl = [nsurl urlwithstring:(nsstring *) [object valueforkey:@"imageurl"]]; nsdata *photodata = [nsdata datawithcontentsofurl:photourl]; [cell.cellimg setimage:[[uiimage alloc] initwithdata:photodata]];         [cell.title settext:[object valueforkey:@"title"]];        return cell; 

here prepareforsegue method

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([[segue identifier] isequaltostring:@"newsdetail"]) {        newsdetailviewcontroller *vc =[segue destinationviewcontroller];       vc.newsdetailimageview = //how designate image cell selected???       vc.newsdetailtext = //how designate text cell selected???                   } } 

this beginners question.... appreciated. given i'm beginner basic example code helps!

if cell selection triggers segue instantly, can make use of indexpathforselecteditems method of uicollectionview indexpath need nsmanagedobject.

try this:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([[segue identifier] isequaltostring:@"newsdetail"]) {         newsdetailviewcontroller *vc =[segue destinationviewcontroller];         // in following line, replace self.collectionview uicollectionview         nsindexpath *indexpath = [[self.collectionview indexpathsforselecteditems] objectatindex:0];          nsmanagedobject *object = [self.fetchedresultscontroller objectatindexpath:indexpath];         nsurl *photourl = [nsurl urlwithstring:(nsstring *)[object valueforkey:@"imageurl"]];         nsdata *photodata = [nsdata datawithcontentsofurl:photourl];         uiimage *img = [[uiimage alloc] initwithdata:photodata];          vc.newsdetailimageview = [[uiimageview alloc] initwithimage:img];         vc.newsdetailtext = howeveryougetyourobjectsummary;                 } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -