Note that there are some explanatory texts on larger screens.

plurals
  1. POTouch Event on image , achieved by using UIButton but show up delayed compare to UIImageView
    primarykey
    data
    text
    <p>Sorry for the messy title, I just don't know how to describe the problem in a delicate way.</p> <p>I'm writing a album-like app to display a bunch of image in my scrollview and do something when a image is touched.</p> <p>I followed this question : <a href="https://stackoverflow.com/q/855095/686011">how can i detect the touch event of an UIImageView</a> and use button with background image to handle touch event.</p> <p>My original method is using NSOperation to concurrently fetch image from internet and put it io a imageview and add to my scrollview, and the speed is quite ok because each imageview shows right after each NSOperation callback.</p> <p>Then I change imageview to uibutton, the strange thing is that when a NSOperation callback, that button does not show in my view. They show up at once when all the NSOperation callback is done. That makes the user experience become unacceptable.</p> <p>This is my NSOperation callback function, it will pass a button that contains the image fetched from internet</p> <pre><code>- (void)imageLoaded:(UIButton*)button; { NSLog(@"Done"); [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } </code></pre> <p>The buttons will only displa after the last "Done" appear instead of one by one, is that normal? or I messed up something?</p> <p>==== update ========</p> <p>I think I'm running the NSOperation on my viewcontroller. I have a imageLoadOperation class, I'll pass my viewcontroller to it</p> <pre><code>imageLoadOperation *ilo = [[imageLoadOperation alloc] initWithURLString:[NSString stringWithFormat:@"link for the image"]; [ilo setParent:self]; [queue addOperation:ilo]; [ilo release]; </code></pre> <p>And in the main function of imageLoadOperation I'll do </p> <pre><code>[parentViewController performSelectorOnMainThread:@selector(imageLoaded:) withObject:button waitUntilDone:NO]; </code></pre> <p>Do you mean I need to move these code to my AppDelegate instead of running in my viewcontrollor?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload