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 が設定されるまで返されないようにすることですが、私が行った方法はあまり信頼できないようです。誰かが正しい方法で私を教育してもらえますか? ありがとう!

ラジコン

4

0 に答える 0