SpaceDust__
SpaceDust__

Reputation: 4914

Send image to another view controller UIImageView IOS 5.1

I have a list of names from Facebook in my uitableview , when user select a row user detail should be shown in another view.

in my friends.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue];

    NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid];

    [facebook requestWithGraphPath:user andDelegate:self];

    FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil];


    profileDetailPicture.profileImage.image= transferImage.image;

    profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentModalViewController:profileDetailPicture animated:YES];

    [profileDetailPicture release];


}

-(void)request:(FBRequest *)request didLoad:(id)result{
    if ([result isKindOfClass:[NSData class]])
    {
       transferImage.image = [[UIImage alloc] initWithData: result];
      // UIImage * sendPicture=[[UIImage alloc] initWithData: result];

        NSLog(@"Profile Picture");
    }
}

This fine because if i put an uiiamgeview below table view to see if it works or not,it seems i get the correct image it works. enter image description here

but when i select the row and try to send the image to other viewcontroller UIImageview in following lines

FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil];


        profileDetailPicture.profileImage.image= transferImage.image;

        profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        [self presentModalViewController:profileDetailPicture animated:YES];

it doesnt send the image to the detail view controller where friends' image should appearenter image description here

I tried both UIImageView and UIImage methods but couldnt make it done.

Whats wrong with the code?

---------EDIT----------

So thanks to answer i have changed the code, following code works fine

-(void)request:(FBRequest *)request didLoad:(id)result{

    if ([result isKindOfClass:[NSData class]])
    {

       transferImage.image = [[UIImage alloc] initWithData: result];

        FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil];

        [profileDetailPicture view];
        profileDetailPicture.profileImage.image= transferImage.image;


        profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        [self presentModalViewController:profileDetailPicture animated:YES];

        [profileDetailPicture release];
        NSLog(@"Profile Picture");
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue];

    NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid];

    [facebook requestWithGraphPath:user andDelegate:self];

}

Upvotes: 0

Views: 1721

Answers (1)

Jesse Rusak
Jesse Rusak

Reputation: 57168

This line is the problem:

profileDetailPicture.profileImage.image= transferImage.image

I'm assuming profileImage is an IBOutlet? The issue is that this will be nil at this point, since your detail view controller's view will not yet be loaded.

The usual way to solve this is to store the image in a member variable of your detail controller and then populate it into the profileImage's image member in viewDidLoad or somewhere else you're sure the detail view is already loaded. (For example, if you were to call [profileDetailPicture view] to force the view to load before this line, it should work.)

Upvotes: 1

Related Questions