2013-02-28 63 views
0

我使用rubymotion与promotion框架来开发我的第一个iOS应用程序。我有一个表格视图(内部导航控制器),点击表格单元格打开新的屏幕与Web视图加载本地HTML文件。问题是Web视图仅在第一次加载时显示。当我返回(导航控制器)并再次点击任何单元时,它会打开新的屏幕,但不会显示网络视图。 Web视图委托方法被触发,所以它加载它,但我只看到黑屏(带有导航栏)。从UITableView加载UIWebView只能第一次工作

这是一个有网络视图的画面代码:

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 

感谢您的任何建议

回答

1

我是一个ProMotion的创造者。通常使用will_appear方法来设置视图元素通常会更好,因为on_load通常会触发得太早以使视图适合bounds。但是,如果您确实加载了will_appear,则需要确保仅实例化Web视图一次(每次切换到该屏幕时都会触发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 
+1

Jamon,感谢您的帮助和您在ProMotion上的工作!它使RubyMotion的开发更愉快:) – 2013-03-01 17:04:15

+0

很高兴听到!那么它的工作,然后呢? – 2013-03-01 17:58:00