0

i have tableview,detailview ,and favoriteview in my app.when user touch cell in tableview will go to detailview thats contain photo,label,textfield and button for add to favorite.user can touch favorite button to add specific cell to favoritetableview. i can succefullly add cell to favoritetableview but when i touch cell in favoritetableview and go to detail view , nothing load in detailtableview ( photo and textfield and etc) just only can send name to detailview how can i send photo and textfield and etc to detailview from favoriteview? how can i reach to detailview from favoriteview same as maintableview?

Any ideas would be appreciated. Thanks.

this is my model photo: [enter image description here][1]

this is prepareforsegue method for every view:

maintableview:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"SpeciesDetail"]) {
        GeneralViewController *detailViewController = (GeneralViewController*)[segue destinationViewController];
        NSIndexPath *path = [self.tableView indexPathForSelectedRow];
        BirdInfo *info;
        BirdImage *imageObj;
        if (!_didSearch) {
            info = (BirdInfo *)[self.fetchedResultsController objectAtIndexPath:path];
            imageObj = info.thumbnailImage;
        } else {
            info =(BirdInfo *)_searchResult[path.row];
        }
        detailViewController.birdName = info.com_name;
        detailViewController.sciName = info.sci_name;
        detailViewController.desbird = info.descriptionbird;
        detailViewController.birdInfo = info;
        detailViewController.managedOjbectContext = self.managedOjbectContext;


    }
}

Favoritetableview:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{



   NSIndexPath *indexPath = (NSIndexPath *)sender;



   // NSIndexPath *indexPath =[self.tableView indexPathForSelectedRow];
    Favorite *fav = (Favorite *)[self.fetchedResultsController objectAtIndexPath:indexPath];





NSString *combinedName = fav.name;




if  ([segue.identifier isEqualToString:@"FavoriteBirdDetail"])
{
    GeneralViewController *detailViewController = (GeneralViewController*)[segue destinationViewController];

    detailViewController.birdName = [combinedName componentsSeparatedByString:@"^"][0];
    NSArray *anArray = [combinedName componentsSeparatedByString:@"^"];

    if ( anArray.count >= 2) {
        detailViewController.sciName = anArray[1];
        //detailViewController.birdInfo=fav.birdInfo;
    }


    detailViewController.managedOjbectContext = self.managedOjbectContext;
}

and my storyboard

enter image description here

  • Hi, Is it necessary to send a textfield to your detail view using segue..?? Please check with that first. On another case instead of sending the complete image you can just pass the image name or url to the details view so that it can fetch the image from DB or can download if required. BTW you can add a textfield on your details view and reuse it as per your requirements, right..!!! – onCompletion Sep 03 '16 at 07:20
  • when detailview come from maintableview everything is ok and all data such as photo ,textile,labels,... load fine;but when detailview come from favoritetableview i can only retrieve label name and another thing dont loaded. – Mehdi Negahban Sep 03 '16 at 07:42
  • are you coming back to detailview from favouritetableview..?? – onCompletion Sep 03 '16 at 08:09
  • yes,but with different segue named "FavoriteBirdDetail". – Mehdi Negahban Sep 03 '16 at 08:30
  • Hey, sorry for little delay. Busy on work. BTW when you are coming back to any viewController from another viewController which you have forwarded then please don't use normal segue. Instead of either use Unwind-segue or it could be best if you are using custom delegate to send back data to parent viewController from child viewController...If you need code explanation then please tell me.. I will post here some code then...:) – onCompletion Sep 05 '16 at 06:51
  • please review my first post.i will be appreciate if you can do that.i don’t know exactly what i must doing. – Mehdi Negahban Sep 05 '16 at 07:04
  • When coming from tableview.m then inside prepareForSegue you are using detailViewController.birdInfo = info; but when you are coming from favorite.m then inside prepareForSegue you are using detailViewController.birdInfo = _birdInfo;. In this case I think you are not assigning any value to _birdInfo. Please do check with that. – onCompletion Sep 05 '16 at 08:00

2 Answers2

0

Passing managedObjectContext from one class to another is completely unnecessary. You can access managedObjectContext from AppDelegate. First of all Check whether you could fetch user info from favourite table by printing the log didselect tableview delegate. Then print the user info in viewdidload method while segueing from favourite VC.

Rokon
  • 355
  • 3
  • 11
  • Please make sure your defined properties are at destination view controller Strong. Passing data from one VC to another VC is not even a matter. May be your error is in somewhere else e.g. your fetch does not return any data. I would be better if you could share your code. – Rokon Sep 05 '16 at 05:49
  • thank you for helping rokon.i done what you told here and also in this post (http://stackoverflow.com/questions/39315143/ios-passing-data-between-two-view-controllers-without-segue/39316046#39316046) but result is same and i can not pass data.data pass successfully to fvc.bird info in button method (in detailviewcontroller) but when pass to favoriteviewcontroller (in viewdidload method) it is null.please see first post here to understand my storyboard.thanks again. – Mehdi Negahban Sep 05 '16 at 06:03
  • please look at the first post to see my sample code. – Mehdi Negahban Sep 05 '16 at 06:13
0

I got your bug. You are assigning _birdInfo property to detailViewController but _birdInfo it self is null. You should set value to _birdInfo before you do detailViewController.birdInfo = _birdInfo;

May be what you are trying to do is:

detailViewController.birdInfo = fav.birdInfo;

// Not detailViewController.birdInfo = _birdInfo;
//_birdInfo is null if you assign to detailViewController.birdInfo will return null too
Rokon
  • 355
  • 3
  • 11
  • but i beforehand assigned birdinfo to birdinfo property of favoriteviewcontroller.here in detailview controller : FavoriteTableViewController *fVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FavoriteTableViewController"]; fVC.birdInfo=_birdInfo; – Mehdi Negahban Sep 05 '16 at 07:15
  • NSLog _birdInfo in prepareForSegue if _birdInfo prints null then you have bug in assigning _birdInfo. Passing data between VC something we do in everyday without even any issue. There are no better way then I have shared. If it does not work please check other issue. May be _birdInfo it self null. – Rokon Sep 05 '16 at 08:06