2010-11-18 31 views

回答

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

我還沒有嘗試過這個,但這是基本的想法。

+0

嗨瑞安,感謝您的答覆。我試過這個,我明白這是主要想法,但它崩潰了,再加上修改handleLoadedApps來清除對象,阻止RSS源最初加載。任何進一步的指導將不勝感激。 – Hanson 2010-11-19 13:28:55

+0

更改'rootViewController.entries = [NSArray數組];'''[rootViewController.imageDownloadsInProgress removeAllObjects];''handleLoadedApps''似乎正在爲我工​​作。在我的情況下,我在'ApplicationWillEnterForeground'中創建一個新的'NSURLConnection' – MrDatabase 2011-12-11 17:48:34

1

(無法找到一個方法來評論...)

我在這裏有同樣的問題,並試圖這種方法。使用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]; 

}

  • (IBAction爲)的重載:(ID)發送方{ [自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; 

}