LazyTableImages for iPhone Sample Code Refresh Question

I am using the LazyTableImages sample code to asynchronously upload a table image from an RSS feed. I would like to know how to reload (restart the parsing operation) in this table after adding a new element specific to this example?

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

many thanks.

+3
source share
2 answers

I think you need to request a download again. You probably want to add a new method to LazyTableAppDelegate that does this, since the class that does the boot is:

- (void)reloadAppList
{
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed]];
    self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
}

, - [LazyTableAppDelegate handleLoadedApps:], , :

- (void)handleLoadedApps:(NSArray *)loadedApps
{
    [self.appRecords removeAllObjects];
    rootViewController.entries = [NSArray array];
    [self.appRecords addObjectsFromArray:loadedApps];

    // tell our table view to reload its data, now that parsing has completed
    [rootViewController.tableView reloadData];
}

, .

+1

( ...)

, . appRecords, removeAllObjects, , .

, :

- (void)applicationDidFinishLaunching:(UIApplication *)application

{   //   [window addSubview: [self.navigationController view]];   [window makeKeyAndVisible];

// Initialize the array of app records and pass a reference to that list to our root view controller
self.appRecords = [NSMutableArray array];
rootViewController.entries = self.appRecords;

//NSURLRequest * urlRequest = [ NSURLRequestWithURL: [NSURL URLWithString: TopPaidAppsFeed]];  //self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest: urlRequest delegate: self] autorelease];

// Test the validity of the connection object. The most likely reason for the connection object
// to be nil is a malformed URL, which is a programmatic error easily detected during development
// If the URL is more dynamic, then you should implement a more flexible validation technique, and
// be able to both recover from errors and communicate problems to the user in an unobtrusive manner.
//
//NSAssert(self.appListFeedConnection != nil, @"Failure to create URL connection.");

// show in the status bar that network activity is starting
// [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self reloadData];

}

  • (IBAction) : (id) { [self reloadData]; }

- (void) reloadData {   NSLog (@ " " );   [self.appRecords removeAllObjects];   // [[myTableViewController imageDownloadsInProgress] removeAllObjects];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed]];
self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];

// Test the validity of the connection object. The most likely reason for the connection object
// to be nil is a malformed URL, which is a programmatic error easily detected during development
// If the URL is more dynamic, then you should implement a more flexible validation technique, and
// be able to both recover from errors and communicate problems to the user in an unobtrusive manner.
//
NSAssert(self.appListFeedConnection != nil, @"Failure to create URL connection.");

// show in the status bar that network activity is starting
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}

+1

Source: https://habr.com/ru/post/1775758/


All Articles