我正在使用LazyTableImages示例代碼在RSS表中異步加載來自RSS提要的表格視圖中的圖像。我想知道的是,一旦添加了一個新項目後,如何重新加載(重新開始解析操作),這個例子是特定的?LazyTableImages for iPhone示例代碼重新加載問題
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
千恩萬謝。
我正在使用LazyTableImages示例代碼在RSS表中異步加載來自RSS提要的表格視圖中的圖像。我想知道的是,一旦添加了一個新項目後,如何重新加載(重新開始解析操作),這個例子是特定的?LazyTableImages for iPhone示例代碼重新加載問題
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
千恩萬謝。
我認爲你需要再次請求下載。你可能要添加到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];
}
我還沒有嘗試過這個,但這是基本的想法。
(無法找到一個方法來評論...)
我在這裏有同樣的問題,並試圖這種方法。使用removeAllObjects清除appRecords,但第二次,所有作品的文章,但圖標不加載。
可以通過改變原始樣品代碼這樣重現問題:
- (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 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];
}
- (無效)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;
}
嗨瑞安,感謝您的答覆。我試過這個,我明白這是主要想法,但它崩潰了,再加上修改handleLoadedApps來清除對象,阻止RSS源最初加載。任何進一步的指導將不勝感激。 – Hanson 2010-11-19 13:28:55
更改'rootViewController.entries = [NSArray數組];'''[rootViewController.imageDownloadsInProgress removeAllObjects];''handleLoadedApps''似乎正在爲我工作。在我的情況下,我在'ApplicationWillEnterForeground'中創建一個新的'NSURLConnection' – MrDatabase 2011-12-11 17:48:34