【发布时间】:2016-11-08 21:25:56
【问题描述】:
尊敬的 iOS 开发人员,
自从使用带有 Xcode 8 Beta 的 iOS 10 Beta 并迁移到 Swift 3 后,我注意到在使用自定义 UITableViewCells 时我的应用程序出现了奇怪的行为。 当我尝试将 cellForRowAtIndexPath 中的自定义单元格出列时,我遇到了 NSException 崩溃 - 除非我在代码中手动注册单元格。但是,并非所有自定义单元格都会发生这种情况,我不知道为什么有些单元格会被注册,而有些则不会。 当我在代码中手动注册单元格时,不会显示自定义内容,而是显示为纯白色。 这意味着 Storyboard 出于某种原因无法正确注册单元格。
- 我正在使用 Prototype Cells。
- Storyboard 和 cellForRowAtIndexPath 中的单元格标识符相同。
- 我正在使用 iOS 10 Beta 2 和 Xcode 8 Beta 2(尽管在第一个 Beta 版中已经出现了这种情况。)
- 我正在使用 Swift 3。
这里有人遇到同样的问题吗?这完全把我逼疯了,我对如何解决这个问题没有任何想法。
-> 这可行,但会导致空白单元格:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.register(ProgressCell.self, forCellReuseIdentifier: Storyboard.progressCell)
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.progressCell) as! ProgressCell
**Configuring the cell here**
return cell
}
-> 这会使应用程序崩溃:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.progressCell) as! ProgressCell
**Configuring the cell here**
return cell
}
Storyboard.progressCell 正在使用我存储所有故事板标识符的结构。
在更新到新版本的 Xcode 和 Swift 3 之前一切正常。
这是崩溃日志:
2016-07-06 20:47:30.049 MYAPP[59012:8826287] -[UIImageView imageOrientation]: unrecognized selector sent to instance 0x7ff5d361f590
2016-07-06 20:47:30.059 MYAPP[59012:8826287] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView imageOrientation]: unrecognized selector sent to instance 0x7ff5d361f590'
*** First throw call stack:
(
0 CoreFoundation 0x000000010614e9bb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001057a731e objc_exception_throw + 48
2 CoreFoundation 0x00000001061badb4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00000001060d4ee5 ___forwarding___ + 1013
4 CoreFoundation 0x00000001060d4a68 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001072236a7 -[UIImageView _updateImageViewForOldImage:newImage:] + 358
6 UIKit 0x000000010721edab -[UIImageView setImage:] + 391
7 UIKit 0x00000001073c57f7 -[UITableViewCell setImage:] + 79
8 Foundation 0x00000001052c8b7f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
9 UIKit 0x00000001070d4195 -[UIView(CALayerDelegate) setValue:forKey:] + 173
10 UIKit 0x000000010740ce72 -[UIRuntimeOutletConnection connect] + 109
11 CoreFoundation 0x00000001060f4bb0 -[NSArray makeObjectsPerformSelector:] + 256
12 UIKit 0x000000010740b7f6 -[UINib instantiateWithOwner:options:] + 1867
13 UIKit 0x0000000107168a0d -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 368
14 UIKit 0x0000000107168f08 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
15 MYAPP 0x0000000104f0808a _TTSf4g_g_d___TFC8MYAPP22ProgressViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 138
16 MYAPP 0x0000000104f0717f _TToFC8MYAPPe22ProgressViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 63
17 UIKit 0x000000010717c16a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 746
18 UIKit 0x000000010717c2c6 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
19 UIKit 0x000000010715053e -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
20 UIKit 0x0000000107185221 -[UITableView _performWithCachedTraitCollection:] + 110
21 UIKit 0x000000010716c1db -[UITableView layoutSubviews] + 222
22 UIKit 0x00000001070d47bf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 956
23 QuartzCore 0x000000010edca278 -[CALayer layoutSublayers] + 146
24 QuartzCore 0x000000010edbdd3c _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
25 UIKit 0x00000001070c290b -[UIView(Hierarchy) layoutBelowIfNeeded] + 275
26 UIKit 0x00000001071f05ea -[UINavigationController _layoutViewController:] + 1625
27 UIKit 0x00000001071ef418 -[UINavigationController _layoutTopViewController] + 341
28 UIKit 0x00000001071ec811 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 874
29 UIKit 0x00000001074c1278 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 418
30 UIKit 0x00000001074c15da -[UINavigationTransitionView _cleanupTransition] + 766
31 UIKit 0x000000010709daed -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
32 UIKit 0x00000001070995bd +[UIViewAnimationState popAnimationState] + 307
33 UIKit 0x00000001074c0fee -[UINavigationTransitionView transition:fromView:toView:] + 2808
34 UIKit 0x00000001071f1697 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3314
35 UIKit 0x00000001071f1c37 -[UINavigationController _startDeferredTransitionIfNeeded:] + 876
36 UIKit 0x00000001071f2d5d -[UINavigationController __viewWillLayoutSubviews] + 58
37 UIKit 0x00000001073da66f -[UILayoutContainerView layoutSubviews] + 223
38 UIKit 0x00000001070d47bf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 956
39 QuartzCore 0x000000010edca278 -[CALayer layoutSublayers] + 146
40 QuartzCore 0x000000010edbdd3c _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
41 QuartzCore 0x000000010edbdbba _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
42 QuartzCore 0x000000010ed4be98 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
43 QuartzCore 0x000000010ed78f7f _ZN2CA11Transaction6commitEv + 475
44 QuartzCore 0x000000010ed798eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
45 CoreFoundation 0x00000001060f4437 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
46 CoreFoundation 0x00000001060f43a7 __CFRunLoopDoObservers + 391
47 CoreFoundation 0x00000001060d8dfe __CFRunLoopRun + 1198
48 CoreFoundation 0x00000001060d86ed CFRunLoopRunSpecific + 285
49 GraphicsServices 0x000000010abfda75 GSEventRunModal + 161
50 UIKit 0x00000001070123b9 UIApplicationMain + 159
51 MYAPP 0x0000000104eda173 main + 99
52 libdyld.dylib 0x0000000109ad768d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
【问题讨论】:
-
你能用 cellForRowAtIndexPath 函数的代码更新你的帖子吗
-
我不明白你为什么要存储很多单元格标识符??你只需要一个
-
我将所有的故事板标识符都存储在其中,例如 segue 标识符和单元标识符。
-
问题是,Interface Builder 将我的插座连接到了错误的类 - 它将类名更改为我在项目中从未使用过的名称,这就是为什么我的其他单元子类发生崩溃的原因。跨度>
-
瓦伦丁,你应该继续post an answer to your own question。
标签: ios swift uitableview storyboard beta