我有一个 UITableView,里面有自定义的 UITableViewCell 和 UITextField。
我想在用户点击单元格时显示键盘。我正在做这样的事情:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "FormCell", for: indexPath) as? FormTableViewCell else {
return
}
cell.textField.becomeFirstResponder()
}
但是当我在 iPad 上运行该应用程序时,点击单元格并尝试使用“关闭键”关闭键盘,我收到此错误:
[Assert] no index path for table cell being reused
这是我得到的全部错误:
* thread #1: tid = 0x7f323, 0x00000001021d5cd8 libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 56, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1021d5cd8)
* frame #0: 0x00000001021d5cd8 libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 56
frame #1: 0x00000001010ab9ec PullToDismiss`@objc PullToDismiss.tableView(UITableView, didEndDisplaying : UITableViewCell, forRowAt : IndexPath) -> () + 104 at PullToDismiss+Proxy.swift:0
frame #2: 0x000000018fb29c9c UIKit`-[UITableView _reuseTableViewCell:withIndexPath:didEndDisplaying:] + 304
frame #3: 0x000000018fa13b58 UIKit`-[UITableView _setIsAncestorOfFirstResponder:] + 1028
frame #4: 0x000000018f8bc288 UIKit`+[UIView(Internal) _setIsResponderAncestorOfFirstResponder:startingAtFirstResponder:] + 216
frame #5: 0x000000018f8bc02c UIKit`-[UIWindow _setFirstResponder:] + 112
frame #6: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #7: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #8: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #9: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #10: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #11: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #12: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #13: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #14: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #15: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #16: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #17: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #18: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #19: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #20: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #21: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #22: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #23: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #24: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #25: 0x000000018f928ecc UIKit`-[UITextField _resignFirstResponder] + 300
frame #26: 0x000000018f8ff374 UIKit`-[UIResponder _finishResignFirstResponder] + 296
frame #27: 0x000000019024d2d0 UIKit`-[UITextField _finishResignFirstResponder] + 52
frame #28: 0x000000018f8a36d0 UIKit`-[UIResponder resignFirstResponder] + 284
frame #29: 0x000000018f928bc8 UIKit`-[UITextField resignFirstResponder] + 136
frame #30: 0x000000018fc25978 UIKit`-[UIKeyboardImpl dismissKeyboard] + 544
frame #31: 0x000000018f9be760 UIKit`-[UIKeyboardLayoutStar continueFromInternationalActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:] + 2544
frame #32: 0x000000018f9bdb7c UIKit`-[UIKeyboardLayoutStar completeSendStringActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:] + 784
frame #33: 0x000000018f9b1684 UIKit`-[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 4712
frame #34: 0x000000018fc3211c UIKit`__45-[UIKeyboardLayout touchUpTaskForTouchState:]_block_invoke + 228
frame #35: 0x000000018f821b14 UIKit`-[UIKeyboardTaskQueue continueExecutionOnMainThread] + 384
frame #36: 0x000000018fc31dd0 UIKit`-[UIKeyboardLayout _touchEndedProcessingForTouches:] + 344
frame #37: 0x000000018f82c0c4 UIKit`-[UIWindow _sendTouchesForEvent:] + 2484
frame #38: 0x000000018f827328 UIKit`-[UIWindow sendEvent:] + 2988
frame #39: 0x000000018f7f7da0 UIKit`-[UIApplication sendEvent:] + 340
frame #40: 0x000000018ffe175c UIKit`__dispatchPreprocessedEventFromEventQueue + 2736
frame #41: 0x000000018ffdb130 UIKit`__handleEventQueue + 784
frame #42: 0x00000001898f6b5c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #43: 0x00000001898f64a4 CoreFoundation`__CFRunLoopDoSources0 + 524
frame #44: 0x00000001898f40a4 CoreFoundation`__CFRunLoopRun + 804
frame #45: 0x00000001898222b8 CoreFoundation`CFRunLoopRunSpecific + 444
frame #46: 0x000000018b2d6198 GraphicsServices`GSEventRunModal + 180
frame #47: 0x000000018f8627fc UIKit`-[UIApplication _run] + 684
frame #48: 0x000000018f85d534 UIKit`UIApplicationMain + 208
frame #49: 0x00000001003da970 `main + 140 at AppDelegate.swift:15
frame #50: 0x00000001888055b8 libdyld.dylib`start + 4
然后应用程序就崩溃了。如果我将 UITableView 滚动到顶部,它也会崩溃。我怎样才能防止这种情况发生?
最佳答案
试试这个方法来获取单元格,你正在做的是创建一个新单元格。
if let cell = tableView.cellForRow(at: indexPath) as? FormTableViewCell {
cell.becomeFirstResponder
} else {
..dostuff
}
关于ios - 断言表格单元格没有索引路径被重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42794181/
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在尝试用Prawn生成PDF。在我的PDF模板中,我有带单元格的表格。在其中一个单元格中,我有一个电子邮件地址:cell_email=pdf.make_cell(:content=>booking.user_email,:border_width=>0)我想让电子邮件链接到“mailto”链接。我知道我可以这样链接:pdf.formatted_text([{:text=>booking.user_email,:link=>"mailto:#{booking.user_email}"}])但是将这两行组合起来(将格式化文本作为内容)不起作用:cell_email=pdf.make_c
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
如何使此根路径转到:“/dashboard”而不仅仅是http://example.com?root:to=>'dashboard#index',:constraints=>lambda{|req|!req.session[:user_id].blank?} 最佳答案 您可以通过以下方式实现:root:to=>redirect('/dashboard')match'/dashboard',:to=>"dashboard#index",:constraints=>lambda{|req|!req.session[:user_id].b
我需要根据字符串路径的长度将字符串路径数组转换为符号、哈希和数组的数组给定以下数组:array=["info","services","about/company","about/history/part1","about/history/part2"]我想生成以下输出,对不同级别进行分组,根据级别的结构混合使用符号和对象。产生以下输出:[:info,:services,about:[:company,history:[:part1,:part2]]]#altsyntax[:info,:services,{:about=>[:company,{:history=>[:part1,:pa
我对单元测试还是比较陌生。我用Ruby编写了一个类,它接受一个文件,在该文件中搜索给定的Regex模式,替换它,然后将更改保存回文件。我希望能够为此方法编写单元测试,但我不知道我将如何去做。有人能告诉我我们如何对处理文件i/o的方法进行单元测试吗? 最佳答案 看看这个HowdoIunit-testsavingfiletothedisk?基本上这个想法是一样的,文件系统是你的类的依赖。所以引入一个可以在你的单元测试中模拟的角色/接口(interface)(这样你在单元测试时就没有依赖性);角色中的方法应该是您从文件系统中需要的所有东西
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
Organization和Image具有一对一的关系。Image有一个名为filename的列,它存储文件的路径。我在Assets管道中包含这样一个文件:app/assets/other/image.jpg。播种时如何包含此文件的路径?我已经在我的种子文件中尝试过:@organization=...@organization.image.create!(filename:File.open('app/assets/other/image.jpg'))#Ialsotried:#@organization.image.create!(filename:'app/assets/other/i
尝试使用rubytest/test_foo.rb运行minitest单元测试时出现以下错误:Warning:youshouldrequire'minitest/autorun'instead.Warning:oradd'gem"minitest"'before'require"minitest/autorun"'From:/home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb:15:```test_foo.rb看起来像这样:require'minitest/autorun'classTestFoo