问题:
我有一个包含 4 个部分的 tableView。在第一部分中,self.performSegueWithIdentifier(String(indexPath.row), sender: self) 工作正常,他们根据他们的 indexPath.row 进行搜索,但是一旦您向下滚动到第二、第三和第四部分并尝试点击它们,indexPath.row 会重置。我希望能够在 tableview 中一直使用 self.performSegueWithIdentifier(String(indexPath.row), sender: self) 而不被部分重置。或者换句话说,我怎样才能对每个部分的单元格进行排序。
示例:
假设在第一部分和第二部分中有 5 个单元格。在第一部分中,5 个单元格连接到正确的 View Controller ,indexPath.row 将它们引导到其中。一旦进入第二部分,indexPath.row 将重置并使用与上面相同的转场。出于隐私原因,数组为空。
代码:
struct Objects {
var cellName : String!
var sectionObjects : [String]!
var detailObjects : [String]!
var imageObjects : [String]!
}
var objectsArray = [Objects]()
objectsArray =
[Objects(cellName: "example",
sectionObjects: [],
detailObjects: [],
imageObjects: []),
Objects(cellName: "example2",
sectionObjects: [],
detailObjects: [],
imageObjects: []),
Objects(cellName: "example3",
sectionObjects: [],
detailObjects: [],
imageObjects: []),
Objects(cellName: "example4",
sectionObjects: [],
detailObjects: [],
imageObjects: [])]
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier(String(indexPath.row), sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
最佳答案
我发现只需在每个部分的 if else 语句中手动设置 segueIdentifier 即可解决我的问题:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 0 {
//art
performSegueWithIdentifier((String(indexPath.row)), sender: nil)
} else if indexPath.section == 1 {
//art galleries
if indexPath.row == 0 {
self.performSegueWithIdentifier("gallery1", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 1 {
self.performSegueWithIdentifier("gallery2", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 2 {
self.performSegueWithIdentifier("gallery3", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 3 {
self.performSegueWithIdentifier("gallery4", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 4 {
self.performSegueWithIdentifier("gallery5", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 5 {
self.performSegueWithIdentifier("gallery6", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
} else if indexPath.section == 2 {
//historic sites
if indexPath.row == 0 {
self.performSegueWithIdentifier("gallery7", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 1 {
self.performSegueWithIdentifier("gallery8", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 2 {
self.performSegueWithIdentifier("gallery9", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 3 {
self.performSegueWithIdentifier("gallery10", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 4 {
self.performSegueWithIdentifier("gallery11", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 5 {
self.performSegueWithIdentifier("gallery12", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
} else if indexPath.section == 3 {
//parks
if indexPath.row == 0 {
self.performSegueWithIdentifier("gallery13", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 1 {
self.performSegueWithIdentifier("gallery14", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 2 {
self.performSegueWithIdentifier("gallery15", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 3 {
self.performSegueWithIdentifier("gallery16", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 4 {
self.performSegueWithIdentifier("gallery17", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if indexPath.row == 5 {
self.performSegueWithIdentifier("gallery18", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
关于swift:在 tableview 部分进行 segueing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34970670/
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
我有一个像这样的ruby类:require'logger'classTdefdo_somethinglog=Logger.new(STDERR)log.info("Hereisaninfomessage")endend测试脚本行如下:#!/usr/bin/envrubygem"minitest"require'minitest/autorun'require_relative't'classTestMailProcessorClasses当我运行这个测试时,out和err都是空字符串。我看到消息打印在stderr上(在终端上)。有没有办法让Logger和capture_io一起玩得
我正在构建一个小部件来显示奥运会的奖牌数。我有一个“国家”对象的集合,其中每个对象都有一个“名称”属性,以及奖牌计数的“金”、“银”、“铜”。列表应该排序:1.首先是奖牌总数2.如果奖牌相同,按类型分割(金>银>铜,即2金>1金+1银)3.如果奖牌和类型相同,则按字母顺序子排序我正在用ruby做这件事,但我想语言并不重要。我确实找到了一个解决方案,但如果感觉必须有更优雅的方法来实现它。这是我做的:使用加权奖牌总数创建一个虚拟属性。因此,如果他们有2个金牌和1个银牌,加权总数将为“3.020100”。1金1银1铜为“3.010101”由于我们希望将奖牌数排序为最高的,因此列表按降序排
我想用sunspot重现以下原始solr查询q=exact_term_text:fooORterm_textv:foo*ORalternate_text:bar*但我无法通过标准的太阳黑子界面理解这是否可能以及如何实现,因为看起来:fulltext方法似乎不接受多个文本/搜索字段参数我不知道将什么参数作为第一个参数传递给fulltext,就好像我通过了"foo"或"bar"结果不匹配如果我传递一个空参数,我得到一个q=*:*范围过滤器(例如with(:term).starting_with('foo*')(顾名思义)作为过滤器查询应用,因此不参与评分。似乎可以手动编写字符串(或者可能使