将图像发送到另一个视图控制器UIImageView IOS 5.1

时间:2012-06-24 23:58:55

标签: objective-c ios uitableview uiimageview uiimage

我的uitableview中有来自Facebook的名单,当用户选择行时,用户详细信息应显示在另一个视图中。

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");
    }
}

这很好,因为如果我在表格视图下方放置一个uiiamgeview以查看它是否有效,我似乎可以得到正确的图像。 enter image description here

但是当我选择行并尝试将图像发送到以下行中的其他viewcontroller UIImageview时

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


        profileDetailPicture.profileImage.image= transferImage.image;

        profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        [self presentModalViewController:profileDetailPicture animated:YES];

它不会将图像发送到详细视图控制器,其中朋友的图像应显示为enter image description here

我尝试了UIImageView和UIImage方法,但无法完成。

代码有什么问题?

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

所以感谢回答我已经更改了代码,以下代码正常工作

-(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];

}

1 个答案:

答案 0 :(得分:1)

这一行是问题所在:

profileDetailPicture.profileImage.image= transferImage.image

我假设profileImage是一个IBOutlet?问题是此时此值为零,因为尚未加载详细视图控制器的视图。

解决此问题的常用方法是将图像存储在详细控制器的成员变量中,然后将其填充到viewDidLoad中的profileImage的图像成员中,或者您确定已加载详细视图的其他位置。 (例如,如果您要调用[profileDetailPicture view]强制视图在此行之前加载,它应该可以工作。)