我正在使用ProMotion,Teacup和MMDrawerController的组合。当我加载应用程序时,一切正常,但是当我尝试从一个屏幕更改为另一个屏幕时,我发现了一个错误,因为superview是零。 Teacup错误是:
*** Terminating app due to uncaught exception 'NoMethodError', reason: 'calculations.rb:15:in calculate:': undefined method 'bounds' for nil:NilClass (NoMethodError)
。这是因为view.superview为null。
我是初学者,但感觉就像Teacup错误只是我设置一切,或者可能与MMDrawerController不兼容的方式出现更大问题的症状。
因此,应用程序加载,转到WeekScreen,在WeekScreen上,我添加一个带有按钮的导航栏,返回到WeekScreen。当我点击该按钮时,我收到错误。 (我在这里简化了代码 - 我真的没有带有按钮的单页应用程序回到同一个屏幕)
屏幕/ root_screen.rb
class RootScreen < MMDrawerController
include PM::ScreenModule
title 'Schedule'
def self.new(args = {})
alloc.init.tap do |root_screen|
root_screen.on_create(args)
end
end
def centerViewController=(centerViewController)
super
self.title = centerViewController.title
end
def on_create(args={})
super
self.leftDrawerViewController = Screen::MenuScreen.new(nav_bar: false)
self.rightDrawerViewController = nil
self.centerViewController = week_screen
leftDrawerButton = MMDrawerBarButtonItem.alloc.initWithTarget self, action:"show_menu:"
navigationItem.setLeftBarButtonItem leftDrawerButton, animated:true
end
def will_appear
self.title = centerViewController.title
end
def show_menu(sender)
toggleDrawerSide MMDrawerSideLeft, animated:true, completion: nil
end
def week_screen
@week_screen ||= Screen::WeekScreen.new
end
end
屏幕/ week_screen.rb
module Screen
class WeekScreen < PM::Screen
title ''
stylesheet :week_styles
include Teacup::TableViewDelegate
@@cell_identifier = nil
@selected_date = nil
def will_appear
super
# mm_drawerController.title = title
view.subviews.each &:removeFromSuperview
layout(view, :main_view) do |main_view|
week_table
subview(UIView, :program_nav) do
@week_btn = subview(UIButton.buttonWithType(UIButtonTypeRoundedRect), :week_btn)
end
@week_btn.when_tapped do
open WeekScreen.new(nav_bar: true)
end
end
end
# a bunch of table stuff removed here to keep this clean-ish
end
end
风格/ week_styles.rb
Teacup::Stylesheet.new :week_styles do
style :main_view,
frame: [[0,30], ["100%", "100% - 30]]
style :program_nav,
frame: [[0, "100% - 78"], ["100%", 78]],
backgroundColor: "#f1f2f2".to_color,
autoresizingMask: (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin)
style :week_btn,
center_x: '50%',
center_y: '50%',
width: 36,
height: 36,
backgroundImage: UIImage.imageNamed("week-view-btn")
end
答案 0 :(得分:0)
尝试将来电on_create
移至on_load
内。屏幕的view
属性在nil
区块内init.tap
。