0

私は最初のiOSアプリケーションを開発するために、プロモーションフレームワークでrubymotionを使用しています。テーブルビュー(ナビゲーションコントローラー内)があります。テーブルセルをタップすると、ローカルhtmlファイルをロードするWebビューで新しい画面が開きます。問題は、Webビューを初めてロードしたときにのみ表示されることです。(ナビゲーションコントローラー)に戻ってセルをもう一度タップすると、新しい画面が開きますが、Webビューが表示されません。Webビューデリゲートメソッドがトリガーされるため、ロードされますが、黒い画面(ナビゲーションバー付き)しか表示されません。

Webビューを備えた画面のコードは次のとおりです。

class XXXDetailScreen < ProMotion::Screen

  attr_accessor :screen_title

  def on_load
    XXXDetailScreen.title = self.screen_title

    @web_view = add_element UIWebView.alloc.initWithFrame(self.view.bounds)
    @web_view.delegate = self
    @web_view.scrollView.scrollEnabled = false
    @web_view.scrollView.bounces = false

    @web_view.loadRequest(NSURLRequest.requestWithURL(NSURL.fileURLWithPath(NSBundle.mainBundle.pathForResource('index', ofType: 'html', inDirectory: 'html'))))
  end

  def webView(inWeb, shouldStartLoadWithRequest: inRequest, navigationType: inType)
    true
  end
end

上の画面は次のコードで開きます:

def tableView(tableView, didSelectRowAtIndexPath: indexPath)
    tableView.deselectRowAtIndexPath(indexPath, animated: true)

    open GalleryDetailScreen.new(screen_title: @data[indexPath.row][:title]), hide_tab_bar: true
end

提案をありがとう

4

1 に答える 1

1

私は ProMotion の作成者の 1 人です。通常will_appear、on_load はビューの適切なbounds. ただし、ロードする場合はwill_appear、Web ビューを 1 回だけインスタンス化する必要があります (will_appearその画面に切り替えるたびに起動します)。

私はデモンストレーションします:

class XXXDetailScreen < ProMotion::Screen

  attr_accessor :screen_title

  def on_load
    XXXDetailScreen.title = self.screen_title
  end

  def will_appear
    add_element draw_web_view
  end

  def draw_web_view
    @web_view ||= begin
      v = UIWebView.alloc.initWithFrame(self.view.bounds)
      v.delegate = self
      v.scrollView.scrollEnabled = false
      v.scrollView.bounces = false

      v.loadRequest(NSURLRequest.requestWithURL(NSURL.fileURLWithPath(NSBundle.mainBundle.pathForResource('index', ofType: 'html', inDirectory: 'html'))))
      v
    end
  end

  def webView(inWeb, shouldStartLoadWithRequest: inRequest, navigationType: inType)
    true
  end
end

:screen_title補足として、アクセサーは本当に必要ありません。ロードするときにこれを行うだけです:

open GalleryDetailScreen.new(title: @data[indexPath.row][:title]), hide_tab_bar: true
于 2013-03-01T06:12:52.887 に答える