2010-11-18 5 views
3

私はLazyTableImagesサンプルコードを使用して、RSSフィードからテーブルビューの画像を非同期に読み込みます。私が知りたいのは、この例に特有の新しい項目が追加されたら、この表の再読み込み(解析操作を再開する方法)です。LazyTableImages for iPhoneサンプルコードリロード質問

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

多くの感謝。

答えて

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

+0

'handleLoadedApps'の' rootViewController.entries = [NSArray array]; 'を' [rootViewController.imageDownloadsInProgress removeAllObjects];に変更すると、私のために働いているようです。私の場合、 'ApplicationWillEnterForeground'に新しい' NSURLConnection'を作成します。 – MrDatabase

1

は、私はここに同じ問題を抱えている

(...コメントする方法を見つけることができません)、このアプローチを試してみました。 removeAllObjectsを使用してappRecordsをクリアしましたが、2回目には記事のすべてが機能しますが、アイコンはロードされません。

- (void)applicationDidFinishLaunching:(UIApplication *)application 

{// の設定をして、ウィンドウ を示しています。

あなたは、元のサンプルコードをこのように変更することで問題を再現することができ、[ウィンドウのaddSubview:[self.navigationController]表示]。 [ウィンドウ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)、送信者{ [自己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; 

}