EXC_BAD_ACCESS 点击 uisearchbar 三下
EXC_BAD_ACCESS tapping uisearchbar three times
我正在尝试将 UICollectionView 中的搜索栏实现为 UICollectionViewReusableView
这样我就没有使用 UISearchController 但我正在更改 collectionview 的数据源
在我的自定义布局中,我以这种方式添加搜索栏:
override func prepareLayout() {
super.prepareLayout()
var searchBarAttributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: TeacherSearchbarIdentifier, withIndexPath: NSIndexPath(forItem: 0, inSection: 0))
searchBarAttributes.frame = CGRectMake(0, 0, collectionViewContentSize().width, 44)
searchBarAttributes.zIndex = 100
miscAttributes.append(searchBarAttributes)
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
var attributes = [UICollectionViewLayoutAttributes]()
for (idx, attr) in enumerate(miscAttributes) {
if CGRectIntersection(rect, attr.frame) != CGRectNull {
attributes.append(attr)
}
}
return attributes
}
我这样设置委托:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: kind, forIndexPath: indexPath) as! UICollectionReusableView
if kind == TeacherSearchbarIdentifier {
controller.searchBar = (view as! TeacherSearchView).searchBar
return view
}
}
变量controller
是实现UISearchBarDelegate
协议的UICollectionViewController
委托在searchBar 变量的didSet 中设置。这些是我的代表:
override func scrollViewDidScroll(scrollView: UIScrollView) {
self.view.endEditing(true)
}
func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
searchBar.setShowsCancelButton(true, animated: true)
return true
}
func searchBarShouldEndEditing(searchBar: UISearchBar) -> Bool {
searchBar.setShowsCancelButton(false, animated: true)
searchBar.resignFirstResponder()
return true
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.setShowsCancelButton(false, animated: true)
searchBar.resignFirstResponder()
}
现在是我的问题!
当我点击搜索栏时,键盘出现了。如果我按下取消按钮或滚动,它就会消失。就像我想要的那样。这也适用于第二次。
但是!
如果我第三次这样做,我会得到 EXC_BAD_ACCESS:
我尝试打开启用僵尸对象,但没有提供任何信息。
我还尝试对 Zombie Objects 进行分析,它只是在没有任何明显信息的情况下崩溃。
请帮助我解决这个错误,或者给我进一步的调试说明。
编辑 1:
这是 lldb 调试器中 bt all
的输出:
* thread #1: tid = 0x228fc, 0x000000019502fbd0 libobjc.A.dylib`objc_msgSend + 16, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1cda8beb8)
frame #0: 0x000000019502fbd0 libobjc.A.dylib`objc_msgSend + 16
frame #1: 0x000000018328b2f4 CoreFoundation`-[__NSDictionaryM objectForKey:] + 84
frame #2: 0x00000001884a21b8 UIKit`-[UICollectionView _visibleViewDictForElementCategory:elementKind:] + 96
frame #3: 0x0000000187ff6644 UIKit`-[UICollectionView _indexPathForView:ofType:] + 160
frame #4: 0x000000018849c3dc UIKit`-[UICollectionView _setIsAncestorOfFirstResponder:] + 792
frame #5: 0x0000000187ed9418 UIKit`+[UIView(Internal) _setIsResponderAncestorOfFirstResponder:startingAtFirstResponder:] + 164
frame #6: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #7: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #8: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #9: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #10: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #11: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #12: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #13: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #14: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #15: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #16: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #17: 0x0000000187f1b194 UIKit`-[UITextField _becomeFirstResponder] + 60
frame #18: 0x000000018800f300 UIKit`-[UISearchBarTextField _becomeFirstResponder] + 108
frame #19: 0x0000000187e9ad28 UIKit`-[UIResponder becomeFirstResponder] + 392
frame #20: 0x0000000187e9b0ac UIKit`-[UIView(Hierarchy) becomeFirstResponder] + 124
frame #21: 0x0000000187f19de4 UIKit`-[UITextField becomeFirstResponder] + 68
frame #22: 0x0000000187fc9fc4 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 200
frame #23: 0x0000000187fc962c UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 1736
frame #24: 0x0000000187faf070 UIKit`_UIGestureRecognizerSendActions + 276
frame #25: 0x0000000187e486b4 UIKit`-[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 580
frame #26: 0x00000001882b938c UIKit`___UIGestureRecognizerUpdate_block_invoke662 + 60
frame #27: 0x0000000187e0c418 UIKit`_UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 292
frame #28: 0x0000000187e0a7c4 UIKit`_UIGestureRecognizerUpdate + 2504
frame #29: 0x0000000187e4682c UIKit`-[UIWindow _sendGesturesForEvent:] + 1044
frame #30: 0x0000000187e45ee4 UIKit`-[UIWindow sendEvent:] + 660
frame #31: 0x0000000187e19120 UIKit`-[UIApplication sendEvent:] + 264
frame #32: 0x00000001880ba2b8 UIKit`_UIApplicationHandleEventFromQueueEvent + 15424
frame #33: 0x0000000187e17634 UIKit`_UIApplicationHandleEventQueue + 1716
frame #34: 0x0000000183358240 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #35: 0x00000001833574e4 CoreFoundation`__CFRunLoopDoSources0 + 264
frame #36: 0x0000000183355594 CoreFoundation`__CFRunLoopRun + 712
frame #37: 0x00000001832812d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #38: 0x000000018ccdf6fc GraphicsServices`GSEventRunModal + 168
frame #39: 0x0000000187e7ef40 UIKit`UIApplicationMain + 1488
* frame #40: 0x00000001000f0798 My-Project`main + 164 at AppDelegate.swift:14
frame #41: 0x00000001956c6a08 libdyld.dylib`start + 4
thread #2: tid = 0x22939, 0x00000001957c4c24 libsystem_kernel.dylib`kevent64 + 8, queue = 'com.apple.libdispatch-manager'
frame #0: 0x00000001957c4c24 libsystem_kernel.dylib`kevent64 + 8
frame #1: 0x000000010083a588 libdispatch.dylib`_dispatch_mgr_invoke + 276
frame #2: 0x000000010082b09c libdispatch.dylib`_dispatch_mgr_thread + 52
thread #8: tid = 0x229d9, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #7: tid = 0x229da, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #9: tid = 0x229df, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #10: tid = 0x229e1, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #11: tid = 0x229e2, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #12: tid = 0x229e3, 0x00000001957c4e0c libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.NSURLConnectionLoader'
frame #0: 0x00000001957c4e0c libsystem_kernel.dylib`mach_msg_trap + 8
frame #1: 0x00000001957c4c88 libsystem_kernel.dylib`mach_msg + 72
frame #2: 0x0000000183357724 CoreFoundation`__CFRunLoopServiceMachPort + 200
frame #3: 0x0000000183355678 CoreFoundation`__CFRunLoopRun + 940
frame #4: 0x00000001832812d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #5: 0x0000000182d5e594 CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 440
frame #6: 0x00000001842a1db8 Foundation`__NSThread__main__ + 1072
frame #7: 0x000000019587bdc8 libsystem_pthread.dylib`_pthread_body + 164
frame #8: 0x000000019587bd24 libsystem_pthread.dylib`_pthread_start + 160
thread #13: tid = 0x229e6, 0x00000001957df498 libsystem_kernel.dylib`__select + 8, name = 'com.apple.CFSocket.private'
frame #0: 0x00000001957df498 libsystem_kernel.dylib`__select + 8
frame #1: 0x000000018335d128 CoreFoundation`__CFSocketManager + 672
frame #2: 0x000000019587bdc8 libsystem_pthread.dylib`_pthread_body + 164
frame #3: 0x000000019587bd24 libsystem_pthread.dylib`_pthread_start + 160
编辑 2:
我创建了一个产生此错误的独立项目。只是 运行 项目和 tap/cancel 搜索栏几次。
视频:
我向苹果提交了错误报告,他们是这样说的:
Apple Developer Relations
Thanks for the update. Upgrading is the solution then.
We are closing this bug report.
If you have questions regarding the resolution of this issue, please
update your bug report with that information.
Please be sure to regularly check new Apple releases for any updates
that might affect this issue.
基本上他们现在不关心这个问题,因为他们即将发布 iOS 9
我问过保持与 iOS 8 的兼容性的正确方法是什么,错误报告仍然存在。让我们拭目以待!
我在 iOS 8 中想出了一个解决方法。我发现只有当我的补充视图的 kind
字符串是 Swift 字符串时才会发生崩溃。当我使用桥接到 Swift 的 Objective-C 字符串时没有崩溃。我尝试了在 Swift 中显式创建 NSString
的明显想法,甚至尝试在 Swift 中创建 CFString
并桥接它。然而,这些努力都没有成功。
为了轻松验证这一点,请尝试将 TeacherSearchbarIdentifier
更改为来自 UIKit 的 Objective-C 字符串,例如 UICollectionElementKindSectionHeader
.
更严格的解决方法是为您的用例创建 Objective-C 字符串并将其公开给 Swift。例如:
// MyElementKinds.h
@import Foundation;
FOUNDATION_EXPORT NSString *const TeacherSearchbarIdentifier;
// MyElementKinds.m
#import "MyElementKinds.h"
NSString *const TeacherSearchbarIdentifier = @"TeacherSearchbarIdentifier";
我正在尝试将 UICollectionView 中的搜索栏实现为 UICollectionViewReusableView
这样我就没有使用 UISearchController 但我正在更改 collectionview 的数据源
在我的自定义布局中,我以这种方式添加搜索栏:
override func prepareLayout() {
super.prepareLayout()
var searchBarAttributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: TeacherSearchbarIdentifier, withIndexPath: NSIndexPath(forItem: 0, inSection: 0))
searchBarAttributes.frame = CGRectMake(0, 0, collectionViewContentSize().width, 44)
searchBarAttributes.zIndex = 100
miscAttributes.append(searchBarAttributes)
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
var attributes = [UICollectionViewLayoutAttributes]()
for (idx, attr) in enumerate(miscAttributes) {
if CGRectIntersection(rect, attr.frame) != CGRectNull {
attributes.append(attr)
}
}
return attributes
}
我这样设置委托:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: kind, forIndexPath: indexPath) as! UICollectionReusableView
if kind == TeacherSearchbarIdentifier {
controller.searchBar = (view as! TeacherSearchView).searchBar
return view
}
}
变量controller
是实现UISearchBarDelegate
协议的UICollectionViewController
委托在searchBar 变量的didSet 中设置。这些是我的代表:
override func scrollViewDidScroll(scrollView: UIScrollView) {
self.view.endEditing(true)
}
func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
searchBar.setShowsCancelButton(true, animated: true)
return true
}
func searchBarShouldEndEditing(searchBar: UISearchBar) -> Bool {
searchBar.setShowsCancelButton(false, animated: true)
searchBar.resignFirstResponder()
return true
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.setShowsCancelButton(false, animated: true)
searchBar.resignFirstResponder()
}
现在是我的问题!
当我点击搜索栏时,键盘出现了。如果我按下取消按钮或滚动,它就会消失。就像我想要的那样。这也适用于第二次。
但是!
如果我第三次这样做,我会得到 EXC_BAD_ACCESS:
我尝试打开启用僵尸对象,但没有提供任何信息。 我还尝试对 Zombie Objects 进行分析,它只是在没有任何明显信息的情况下崩溃。
请帮助我解决这个错误,或者给我进一步的调试说明。
编辑 1:
这是 lldb 调试器中 bt all
的输出:
* thread #1: tid = 0x228fc, 0x000000019502fbd0 libobjc.A.dylib`objc_msgSend + 16, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1cda8beb8)
frame #0: 0x000000019502fbd0 libobjc.A.dylib`objc_msgSend + 16
frame #1: 0x000000018328b2f4 CoreFoundation`-[__NSDictionaryM objectForKey:] + 84
frame #2: 0x00000001884a21b8 UIKit`-[UICollectionView _visibleViewDictForElementCategory:elementKind:] + 96
frame #3: 0x0000000187ff6644 UIKit`-[UICollectionView _indexPathForView:ofType:] + 160
frame #4: 0x000000018849c3dc UIKit`-[UICollectionView _setIsAncestorOfFirstResponder:] + 792
frame #5: 0x0000000187ed9418 UIKit`+[UIView(Internal) _setIsResponderAncestorOfFirstResponder:startingAtFirstResponder:] + 164
frame #6: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #7: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #8: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #9: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #10: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #11: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #12: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #13: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #14: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #15: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #16: 0x0000000187ed925c UIKit`-[UIResponder(Static) _setFirstResponder:] + 56
frame #17: 0x0000000187f1b194 UIKit`-[UITextField _becomeFirstResponder] + 60
frame #18: 0x000000018800f300 UIKit`-[UISearchBarTextField _becomeFirstResponder] + 108
frame #19: 0x0000000187e9ad28 UIKit`-[UIResponder becomeFirstResponder] + 392
frame #20: 0x0000000187e9b0ac UIKit`-[UIView(Hierarchy) becomeFirstResponder] + 124
frame #21: 0x0000000187f19de4 UIKit`-[UITextField becomeFirstResponder] + 68
frame #22: 0x0000000187fc9fc4 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 200
frame #23: 0x0000000187fc962c UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 1736
frame #24: 0x0000000187faf070 UIKit`_UIGestureRecognizerSendActions + 276
frame #25: 0x0000000187e486b4 UIKit`-[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 580
frame #26: 0x00000001882b938c UIKit`___UIGestureRecognizerUpdate_block_invoke662 + 60
frame #27: 0x0000000187e0c418 UIKit`_UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 292
frame #28: 0x0000000187e0a7c4 UIKit`_UIGestureRecognizerUpdate + 2504
frame #29: 0x0000000187e4682c UIKit`-[UIWindow _sendGesturesForEvent:] + 1044
frame #30: 0x0000000187e45ee4 UIKit`-[UIWindow sendEvent:] + 660
frame #31: 0x0000000187e19120 UIKit`-[UIApplication sendEvent:] + 264
frame #32: 0x00000001880ba2b8 UIKit`_UIApplicationHandleEventFromQueueEvent + 15424
frame #33: 0x0000000187e17634 UIKit`_UIApplicationHandleEventQueue + 1716
frame #34: 0x0000000183358240 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #35: 0x00000001833574e4 CoreFoundation`__CFRunLoopDoSources0 + 264
frame #36: 0x0000000183355594 CoreFoundation`__CFRunLoopRun + 712
frame #37: 0x00000001832812d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #38: 0x000000018ccdf6fc GraphicsServices`GSEventRunModal + 168
frame #39: 0x0000000187e7ef40 UIKit`UIApplicationMain + 1488
* frame #40: 0x00000001000f0798 My-Project`main + 164 at AppDelegate.swift:14
frame #41: 0x00000001956c6a08 libdyld.dylib`start + 4
thread #2: tid = 0x22939, 0x00000001957c4c24 libsystem_kernel.dylib`kevent64 + 8, queue = 'com.apple.libdispatch-manager'
frame #0: 0x00000001957c4c24 libsystem_kernel.dylib`kevent64 + 8
frame #1: 0x000000010083a588 libdispatch.dylib`_dispatch_mgr_invoke + 276
frame #2: 0x000000010082b09c libdispatch.dylib`_dispatch_mgr_thread + 52
thread #8: tid = 0x229d9, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #7: tid = 0x229da, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #9: tid = 0x229df, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #10: tid = 0x229e1, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #11: tid = 0x229e2, 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x00000001957dfc78 libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x00000001958792dc libsystem_pthread.dylib`_pthread_wqthread + 992
thread #12: tid = 0x229e3, 0x00000001957c4e0c libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.NSURLConnectionLoader'
frame #0: 0x00000001957c4e0c libsystem_kernel.dylib`mach_msg_trap + 8
frame #1: 0x00000001957c4c88 libsystem_kernel.dylib`mach_msg + 72
frame #2: 0x0000000183357724 CoreFoundation`__CFRunLoopServiceMachPort + 200
frame #3: 0x0000000183355678 CoreFoundation`__CFRunLoopRun + 940
frame #4: 0x00000001832812d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #5: 0x0000000182d5e594 CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 440
frame #6: 0x00000001842a1db8 Foundation`__NSThread__main__ + 1072
frame #7: 0x000000019587bdc8 libsystem_pthread.dylib`_pthread_body + 164
frame #8: 0x000000019587bd24 libsystem_pthread.dylib`_pthread_start + 160
thread #13: tid = 0x229e6, 0x00000001957df498 libsystem_kernel.dylib`__select + 8, name = 'com.apple.CFSocket.private'
frame #0: 0x00000001957df498 libsystem_kernel.dylib`__select + 8
frame #1: 0x000000018335d128 CoreFoundation`__CFSocketManager + 672
frame #2: 0x000000019587bdc8 libsystem_pthread.dylib`_pthread_body + 164
frame #3: 0x000000019587bd24 libsystem_pthread.dylib`_pthread_start + 160
编辑 2: 我创建了一个产生此错误的独立项目。只是 运行 项目和 tap/cancel 搜索栏几次。
视频:
我向苹果提交了错误报告,他们是这样说的:
Apple Developer Relations
Thanks for the update. Upgrading is the solution then.
We are closing this bug report.
If you have questions regarding the resolution of this issue, please update your bug report with that information.
Please be sure to regularly check new Apple releases for any updates that might affect this issue.
基本上他们现在不关心这个问题,因为他们即将发布 iOS 9
我问过保持与 iOS 8 的兼容性的正确方法是什么,错误报告仍然存在。让我们拭目以待!
我在 iOS 8 中想出了一个解决方法。我发现只有当我的补充视图的 kind
字符串是 Swift 字符串时才会发生崩溃。当我使用桥接到 Swift 的 Objective-C 字符串时没有崩溃。我尝试了在 Swift 中显式创建 NSString
的明显想法,甚至尝试在 Swift 中创建 CFString
并桥接它。然而,这些努力都没有成功。
为了轻松验证这一点,请尝试将 TeacherSearchbarIdentifier
更改为来自 UIKit 的 Objective-C 字符串,例如 UICollectionElementKindSectionHeader
.
更严格的解决方法是为您的用例创建 Objective-C 字符串并将其公开给 Swift。例如:
// MyElementKinds.h
@import Foundation;
FOUNDATION_EXPORT NSString *const TeacherSearchbarIdentifier;
// MyElementKinds.m
#import "MyElementKinds.h"
NSString *const TeacherSearchbarIdentifier = @"TeacherSearchbarIdentifier";