English 中文(简体)
UIButton形象
原标题:UIButton image asynchronously

我有一个UIButton的浮板,位于UIScrollView中,每个UIButton从URL中摄取图像。 如何最容易地把图像装上同步?

例如,通常的做法是:

[button setImage:[UIImage imageWithData:data] forState:UIControlStateNormal];

但这并不是万能的。

最佳回答

你可以尝试这样做。

     [self performSelectorInBackground:@selector(loadImag) withObject:nil];

In loadImage function load the image from url and then assign it to the button. I am not sure this will work for you...As I am a beginner in objective C development

问题回答

与国家职业安全局合作,对每个图像区提出同步要求。 穿过 but子作为直径,例如这意味着......

• 在行动地点(可能位于内地):

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

1. 启动每个纽州的工作......

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self 
                                                                        selector:@selector(getImageFromURL:) 
                                                                          object:[NSDictionary dictionaryWithObjectsAndKeys:@"http://getMyImage.com/resource.jpg", @"url", button, @"button", nil]];

[queue addOperation:operation];
[operation release];

∗∗∗∗ 甄选者

- (void) getImageFromURL:(NSDictionary*)dict
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSURL *url = [NSURL URLFromString:[dict objectForKey:@"url"]];
    UIButton *button = [dict objectForKey:@"button"];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
    UIImage *image = [[UIImage alloc] initWithData:data];

    // Finally set the button image and release image ...
    [pool drain];
}

Don tabe release queue on dealloc.

希望:

我猜测,如果你在装上单一图像时加以阻挡,那是 al吗? 问题是,你们有许多? 如果是的话,那么我会这样做(不需要的线索):

#define DELAY 0.1 // you may set it to 0 as well

    ...
    [self performSelector:@selector(setupButton:)
               withObject:[NSNumber numberWithInt:0]
               afterDelay:DELAY];
    ...

-(void)setupButton:(NSNumber*)count
{
    UIButton *button = [self buttonFromMyScrollViewWithCount:count.intValue];
    [button setImage:...];
    if (count.intValue < self.numberOfButtonsInMyScrollView)
        [self performSelector:@selector(setupButton:)
                   withObject:[NSNumber numberWithInt:count.intValue + 1]
                   afterDelay:DELAY];
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签