Delayed UIImageView Rendering in UITableView

后端 未结 4 1205
清歌不尽
清歌不尽 2020-12-12 12:56

Ok, I\'ve got a UITableView with custom UITableViewCells that each contain a UIImageView whose images are being downloaded asynchronou

4条回答
  •  [愿得一人]
    2020-12-12 14:01

    The reason the connection delegate messages aren't firing until you stop scrolling is because during scrolling, the run loop is in UITrackingRunLoopMode. By default, NSURLConnection schedules itself in NSDefaultRunLoopMode only, so you don't get any messages while scrolling.

    Here's how to schedule the connection in the "common" modes, which includes UITrackingRunLoopMode:

    NSURLRequest *request = ...
    NSURLConnection *connection = [[NSURLConnection alloc]
                                   initWithRequest:request
                                   delegate:self
                                   startImmediately:NO];
    [connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
                forMode:NSRunLoopCommonModes];
    [connection start];
    

    Note that you have to specify startImmediately:NO in the initializer, which seems to run counter to Apple's documentation that suggests you can change run loop modes even after it has started.

提交回复
热议问题