send data to DetailView from FavoriteTableView?

自作多情 提交于 2019-12-12 04:39:26

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/39304240/send-data-to-detailview-from-favoritetableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!