Xcode Master Detail应用程序后退按钮属性(Xcode Master Detail Application back button properties)
如何在导航栏中添加“后退按钮”的属性? 该按钮从详细视图链接到主视图。 我找不到后退按钮的任何代码,并且该按钮隐藏在故事板视图中。
How do I add properties for the "back button" in the navigation bar? The button links from detail view and back to the master view. I can't find any code for the back button, and the button is hidden in storyboard view.
原文:https://stackoverflow.com/questions/28188475
最满意答案
一个简单的方法就是在模型中有以下关系
belongs_to :master_product, :foreign_key => : master_prouduct_id, :class_name => "Product"
通过在任何产品对象上调用master_product,我们可以获得主对象。
但是这种实现需要应用程序逻辑来处理是否调用master_product。
别担心,我们可以按照下面的其他方式,
Product < AR::Base def self.find(id) rec = super(id) rec.master_product_id ? super(rec.master_product_id) : rec end end
但是,这样我们就不会使用find来获得儿童产品,即使我们也希望获得儿童产品。 所以,我建议为此使用不同的函数名称,或者在查找定义中有一个标志,它自己告诉要求。
仍然,您需要处理其他方案(Where,Joins,Associations等)。
我不确定rails是否对此有任何支持。
one simple way you can do is, having following relation in model
belongs_to :master_product, :foreign_key => : master_prouduct_id, :class_name => "Product"
by calling master_product on any product object we can get master object.
But this implementation needs application logic to handle whether to call master_product or not.
Don't worry, we can follow other way as below,
Product < AR::Base def self.find(id) rec = super(id) rec.master_product_id ? super(rec.master_product_id) : rec end end
But, In this way we wont get the child products at all using find, even if we want to get child products also. So, i suggest to use different function name for this or have a flag in find definition it self to tell the requirement.
Still, You need to handle other scenarios(Where, Joins, Associations etc).
Iam not sure whether rails had any support for this.
相关问答
更多-
linux 结构体命名规则[2024-03-18]
record -
向用户添加关系: class User < ActiveRecord::Base # Your current code has_one :house, -> { where('houses.id IN (SELECT min(id) FROM houses GROUP BY user_id)')} end 然后,您的查询将是: users = User.joins(:house) - 更新如果您想过滤结果,请自由添加where子句 users = User.joins(:house).wher ...
-
一个简单的方法就是在模型中有以下关系 belongs_to :master_product, :foreign_key => : master_prouduct_id, :class_name => "Product" 通过在任何产品对象上调用master_product,我们可以获得主对象。 但是这种实现需要应用程序逻辑来处理是否调用master_product。 别担心,我们可以按照下面的其他方式, Product < AR::Base def self.find(id) re ...
-
要使用通用的“市场”控制器,您需要为每个继承的模型设置其他资源,同时指定要使用的控制器 。 以EbayMarket为例,您可以将以下行添加到routes.rb文件中: resource :ebay_markets, :controller => "markets" 如果您希望避免重复,请参阅路由问题 。 Okay.. I wanted to be able to add the routs for an inherited class, with as little code as possible. I ...
-
在实践中,只要你保留对这个实例的引用。 在大多数情况下 - 直到请求完成。 class Model # most common memoization pattern def something @cached_result ||= do_query end end 因此,当您的模型将被实例化时(在控制器/服务/等中),只要您可以引用它,它就会可用。 在下一个请求中,将重新计算@cached_result 。 如果要在请求之间缓存某些内容,可以使用CacheStore: class M ...
-
循环遍历从第三个到最后一个活动记录对象的每个元素(Loop through each element from third to last of active record object)[2022-05-27]
使用Array#drop方法删除@obj的前两个元素: @obj.drop(2).each do |obj| # whatever... end Use the Array#drop method to drop the first two elements of @obj: @obj.drop(2).each do |obj| # whatever... end -
如何根据条件简化Rails Active Record计算?(How to simplify Rails Active Record calculation based on condition?)[2023-12-06]
class Job < ActiveRecord::Base scope :super_jobs, -> {where('super_condition')} end jobs = jobs.super_jobs unless some_condition jobs.sum("my_field") class Job < ActiveRecord::Base scope :super_jobs, -> {where('super_condition')} end jobs = jobs.sup ... -
但是任务2从未在10秒后看到更新和超时,而没有处理 我怀疑缓存问题( Query.find(query_id)命中缓存而不是数据库)。 尝试在每次重试时使用q.reload而不是q = Query.find(query_id) 。 或者,更好的是,在Task1完成时安排Task2,这样您就不必长时间地绑定您的工作人员。 But Task 2 never sees the update & times out after 10 secs, without processing I'm suspecting c ...
-
活动记录codeigniter(active record codeigniter)[2023-07-27]
$query = $this->db ->select('u.token') ->from('user u') ->where('u.userid', $id) ->get(); return ($query->num_rows() == 1) ? $query->row()->token : 0; $query = $this->db ->select('u.token') ->from('user u') ->where(' ... -
您可以子类化位于系统数据库中的CI_DB_active_record类。 并修改插入方法以忽略您不想保存的属性。 这将向您展示如何加载它。 它需要稍微修改才能在/system/DB.php加载子类 只是为了记录,可能有更好的方法来做你想要完成的事情。 You can subclass the CI_DB_active_record class located in system database. And modify the insert method to ignore your attributes ...