我只使用Promotion-Menu's Readme中显示的代码完成了一个新项目。我有这个:
# app_delegate.rb
class AppDelegate < PM::Delegate
def on_load(app, options)
@menu = open MenuDrawer
end
def show_menu
@menu.show :left
end
end
#menu_drawer.rb
class MenuDrawer < PM::Menu::Drawer
def setup
self.center = HomeScreen.new(nav_bar: true)
self.left = NavigationScreen
self.to_show = [:pan_bezel, :pan_nav_bar]
self.transition_animation = :swinging_door
self.max_left_width = 250
self.shadow = false
end
end
#navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'OVERWRITE THIS METHOD',
action: :swap_center_controller,
arguments: HomeScreen
}]
}]
end
def swap_center_controller(screen_class)
app_delegate.menu.center_controller = screen_class
end
end
我的应用正在运行但是没有侧边栏,您可以在此处看到:
我错过了什么吗?
答案 0 :(得分:4)
没有。你有什么应该工作。您必须平移挡板或导航栏以显示左侧控制器(首次打开应用程序时隐藏)。我一直在考虑在示例中添加一个菜单按钮,以使其更加清晰。以下是可行的方法:
# home_screen.rb
class HomeScreen < PM::Screen
title "Home"
def on_load
set_nav_bar_button :right, title: "Menu", action: :open_menu
end
def open_menu
app_delegate.show_menu
end
end
# navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'HomeScreen',
action: :swap_center_controller,
arguments: HomeScreen.new(nav_bar: true)
},{
title: 'HelpScreen',
action: :swap_center_controller,
arguments: HelpScreen.new(nav_bar: true)
}]
}]
end
def swap_center_controller(screen)
app_delegate.menu.center_controller = screen
app_delegate.menu.hide
end
end
您的AppDelegate
和MenuDrawer
将保持不变。