适用于iPhone的LazyTableImages示例代码重新加载问题

时间:2010-11-18 23:23:25

标签: iphone xcode

我正在使用LazyTableImages示例代码从RSS源中异步加载表格视图中的图像。我想知道的是,一旦添加了新项目,如何在此表中重新加载(重新启动解析操作),特定于此示例?

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

非常感谢。

2 个答案:

答案 0 :(得分:1)

我认为您需要再次请求下载。您可能希望向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];
}

我自己没试过,但那是基本的想法。

答案 1 :(得分:1)

(无法找到评论方式......)

我在这里遇到同样的问题,并尝试了这种方法。使用removeAllObjects清除appRecords,但第二次,所有文章都适用,但图标没有加载。

您可以通过以下方式更改原始示例代码来重现此问题:

- (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 = [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)reload:(id)sender { [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;

}