From 0bcb0dbe460de0a457c8229a4d437fe5384a2498 Mon Sep 17 00:00:00 2001 From: geophyli Date: Sun, 11 Sep 2016 20:08:07 +0800 Subject: [PATCH] Update ios-guide-04.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了navigation_screen的步骤以及代码 --- ios-guide-04.md | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/ios-guide-04.md b/ios-guide-04.md index 2cfc78d..2f1653b 100644 --- a/ios-guide-04.md +++ b/ios-guide-04.md @@ -136,4 +136,123 @@ end ## Step 6 : +* potion g screen navigation + +修改 app/screens/navigation_screen.rb +``` +class NavigationScreen < PM::TableScreen + + def on_load + rmq.stylesheet = NavigationScreenStylesheet + end + + def table_data + + [{ + title: nil, + cells: [ + { title: '' }, + { title: sign_in_out_title , + action: :sign_in_out_button, + }, + { title: 'Sign Up', + action: :sign_up_button, + }, + add_credit_card_menu + ] + }] + end + + def add_credit_card_menu + if Auth.signed_in? + { title: "Add Credit Card", action: :add_credit_card_action } + end + end + + def sign_in_out_title + if Auth.signed_in? + "Logout" + else + "Sign In" + end + end + + def sign_in_out_button + if Auth.signed_in? + sign_out_button + else + sign_in_button + end + end + + def sign_in_button + open SignInScreen.new(nav_bar: true) + end + + def sign_up_button + open SignUpScreen.new(nav_bar: true) + end + + def sign_out_button + Auth.sign_out do + app.delegate.open_authenticated_root + end + end + + def add_credit_card_action + open AddCreditCardScreen.new(nav_bar: true) +# open PaymentViewController.new +# mp StripeConnection.connectionWithPublishableKey("pk_test_APfRAnKNxAO78IG481nvbXqq") + end + + + def swap_center_controller(screen_class) + # Just use screen_class if you don't need a navigation bar + app_delegate.menu.center_controller = screen_class + end + + + # You don't have to reapply styles to all UIViews, if you want to optimize, another way to do it + # is tag the views you need to restyle in your stylesheet, then only reapply the tagged views, like so: + # def logo(st) + # st.frame = {t: 10, w: 200, h: 96} + # st.centered = :horizontal + # st.image = image.resource('logo') + # st.tag(:reapply_style) + # end + # + # Then in will_animate_rotate + # find(:reapply_style).reapply_styles# + + # Remove the following if you're only using portrait + def will_animate_rotate(orientation, duration) + reapply_styles + end +end + +``` + +修改 app/stylesheets/navigation_screen_stylesheet.rb + +``` +class NavigationScreenStylesheet < ApplicationStylesheet + # Add your view stylesheets here. You can then override styles if needed, + # example: include FooStylesheet + + def setup + # Add stylesheet specific setup stuff here. + # Add application specific setup stuff in application_stylesheet.rb + end + + def root_view(st) + st.background_color = color.white + end + +end + +``` + + +## Step 7 : + * rake