0

Web サービスから n 個の URL を取得します。didSelectRowAtIndexPath を選択すると、その特定のファイルの URL を表示する必要があります。すべての行の URL が異なることに注意してください。URLをSaveDisplayクラスに保存し、SaveDisplay.mクラスには次のコードがあります

「SaveDisplay.h」をインポートします

@implementation SaveDisplay
@synthesize buttonName;
@synthesize urlForLoad;

- (id) initWithButtonName:(NSString *)_buttonName withUrlForLoad:(NSString *)_urlForLoad
{
    self = [super init];
    if(self)
    {
        self -> buttonName = _buttonName;
        self -> urlForLoad = _urlForLoad;
    }
    return self;
}

@end

これが私が試みていることですが、それをループしてそれぞれのファイルのURLを設定する適切な方法が必要です

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      
        SaveDisplay *objectForUrl = [[SaveDisplay alloc] init];
            WebViewController *webController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:Nil];
             webController.urlToLoad = objectForUrl.urlForLoad;
            [self.navigationController pushViewController:webController animated:YES];
}
    

ここに画像の説明を入力

4

2 に答える 2

0

あなたの SaveDisplay クラスの機能についてはよくわかりません。これを達成するためのより一般的な方法は次のとおりです。

  1. Web サービスから結果を取得する
  2. それらを辞書または配列(またはデータソースとして使用できるもの以外のもの...)に保存します。
  3. テーブルビューを作成します (2 のデータソースから)。
  4. アイテム選択時
  5. 選択したアイテムの URL を取得します (2. のデータソースから)。
  6. 取得した URL を使用してビュー コントローラーをセットアップする
  7. ビューコントローラーをプッシュ

したがって、次のような便利なメソッドを作成したい場合があります。

- (NSURL *)getURLForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Find and return URL for given index path
    NSURL *documentURL = ...

    return documentURL;
}
于 2013-11-13T13:57:30.640 に答える