快速业务通道

使用Ruby on Rails和Eclipse开发iPhone应用程序,第2部分 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-14
quot;      class="mobile_link">Switch To Desktop View</a></ul>

单击 Most Recent Recipes 条目,界面内容就会向侧面滑动,屏幕如图 3 所示。在这里,iUI JavaScript 更改了标题和 Back 按钮。

图 3. 只有一级的下钻

使用Ruby on Rails和Eclipse开发iPhone应用程序,第2部分 - 编程入门网

要创建这个屏幕,Recipe Controller 的 index 方法需要将 format.iphone {render :layout => false} 放置到它的 respond_to 块中,如下所示。

清单 8. 食谱的索引操作

def index
      @recipes = Recipe.find_for_index(params[:type])
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml => @recipes }
        format.iphone {render :layout => false}
      end
    end

呈现的文件 app/views/recipes/index.iphone.erb 使用了相同的 rails_iui helper 函数。这假设 Recipe 对象能够恰当地响应 helper 函数(<%= iui_list @recipes %>)调用的 caption 和 option_hash 方法。

使用Ruby on Rails和Eclipse开发iPhone应用程序,第2部分(9)

时间:2011-11-29 ibm developerWorks Noel Rappin

使用替换扩展列表

我在前面提到,在 iUI 锚标记中将目标设为 _replace 会导致这个标记调用的结果自动地替换原始列表。这能够使列表的最后一个元素显示某些内容,比如 “Next 25 items”,同时也使新的条目像原始条目一样出现在相同的列表上,便于用户上下滚动整个列表。

要想使用已经构建的 helper 函数实现替换功能,必须通过两种方式扩展 iui_list 方法。列表 helper 函数需要一个选项来为列表添加更多的条目 —— 目前,假设它是列表底部的一个额外选项。然后,对单击的响应需要返回标记为 li 的条目列表,但没有包围的 ul 标记,这个标记已经存在于需要更改的页面中。

这个实现的第一部分是一些特定的 link_to helper 函数,用于管理 iUI 特定的 _replace 和 _self 行为。然后,我将再添加一个方法,根据 target 参数实现不同链接类型的转换。这两种方法如下所示。

清单 9. iUI 链接 helper 函数

def link_to_replace(name, options, html_options = {})
      html_options[:target] = "_replace"
      link_to(name, options, html_options)
    end

    def link_to_external(name, options, html_options = {})
      html_options[:target] = "_self"
      link_to(name, options, html_options)
    end

    def link_to_target(target, name, options, html_options = {})
      if target == :replace 
        link_to_replace(name, options, html_options)
      elsif target == :self or target == :external
        link_to_external(name, options, html_options)
      else
        link_to(name, options, html_options)
      end
    end

准备好链接 helper 函数后,可以扩展 iui_list 函数和附加的 append_options 方法,添加新的功能。

清单 10. iUI 链接 helper 函数

def append_options(list_content, options = {})      list_content = options[:top] + list_content if options[:top]      list_content += list_element(options[:more], :replace) if options[:more]      list_content += options[:bottom] if options[:bottom]      list_content    end    def iui_list(items, options = {})      list_content = items.map {|i| list_element(i)}.join("\n")      list_content = append_options(list_content, options)      if options[:as_replace]         list_content      else      

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号