LazyTableImages для iPhone Пример кода Перезагрузить вопрос - PullRequest
3 голосов
/ 19 ноября 2010

Я использую пример кода LazyTableImages для асинхронной загрузки изображений в виде таблицы из канала RSS.Я хотел бы знать, как перезагрузить (перезапустить операцию разбора) в этой таблице после добавления нового элемента, характерного для этого примера?

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

большое спасибо.

Ответы [ 2 ]

1 голос
/ 02 января 2011

(Не удается найти способ комментировать ...)

У меня та же проблема, и я попробовал этот подход. Очистил appRecords, используя removeAllObjects, но во второй раз все работает для статей, но значки не загружаются.

Вы можете воспроизвести проблему, изменив исходный пример кода следующим образом:

- (void)applicationDidFinishLaunching:(UIApplication *)application

{ // Настройка и отображение окна [окно addSubview: [представление self.navigationController]]; [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 = [NSURLRequest requestWithURL: [NSURL URLWithString: TopPaidAppsFeed]]; //self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest: делегат urlRequest: 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 голос
/ 19 ноября 2010

Я думаю, вам нужно запросить загрузку снова.Возможно, вы захотите добавить новый метод в LazyTableAppDelegate, который делает это, так как это класс, который выполняет начальную загрузку:

- (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];
}

Я сам не пробовал, но это основная идея.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...