1

嗨,有人可以在这里帮助我吗:

[prefs setObject:[self userImage:[i valueForKey:@"username"] whichAccount:i] forKey:@"User Image"];

哪个电话:

- (UIImage *)userImage:(NSString *)name whichAccount:(id)account
{

__block UIImage *image;
__block UIImage *result;

// had to change this to new api: (6/2013)
NSURL *url =
[NSURL URLWithString:@"http://api.twitter.com/1.1/users/show.json"];

NSDictionary *params = [NSDictionary dictionaryWithObject:name
                                                   forKey:@"screen_name"];

TWRequest *request2 = [[TWRequest alloc] initWithURL:url
                                          parameters:params
                                       requestMethod:TWRequestMethodGET];

[request2 setAccount:account];

[request2 performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

    if (responseData) {

        NSDictionary *user =
        [NSJSONSerialization JSONObjectWithData:responseData
                                        options:NSJSONReadingAllowFragments
                                          error:NULL];

        NSString *profileImageUrl = [[user objectForKey:@"profile_image_url"] stringByReplacingOccurrencesOfString:@"_normal" withString:@""];

        NSData *imageData =
        [NSData dataWithContentsOfURL:
         [NSURL URLWithString:profileImageUrl]];

        image = [UIImage imageWithData:imageData];

        UIGraphicsBeginImageContext(CGSizeMake(128 ,128));
        [image drawInRect:CGRectMake(0, 0, 128, 128)];

        result = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

    }
}];

// new way:
while (result == nil)
{
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}

UIImage *OrigImage = result;
UIImage *mask = [UIImage imageNamed:@"image_mask@2x.png"];
UIImage *maskedImage = [UIImage maskImage:OrigImage withMask:mask];

return maskedImage;

}

我想要的是 userImage:whichAccount 在设置 maskedImage 之前不会返回,但我所做的方式似乎不是很可靠。有人可以以正确的方式教育我吗?谢谢!

rc

4

0 回答 0