关于 ios:iPhone 应用程序在选择 UITableViewCell 时冻结 – 在暂停/中断后间歇性地冻结

iPhone app freezes on selecting TableViewCell - intermittently, after pause/break

过去两周我一直在为这个问题苦苦挣扎 - 在搜索我的代码或堆栈溢出后无法找到解决方案。

问题:

我有一个带有表格视图的视图控制器,带有单元格。大多数时候,当我单击其中一个单元格将我推送到另一个视图控制器时,它工作正常。但是有时当我单击一个单元格时,应用程序会冻结。它不会崩溃 - 只是冻结。然后我通常必须按下主页按钮,再次启动应用程序 - 此时启动需要永远,导致应用程序崩溃。然后我再次启动应用程序,它返回到我的应用程序的第一页。

我发现很难复制 - 在正常启动时使用它可以正常工作。当我将应用程序置于后台一段时间或设备锁定时,似乎通常会发生这种情况。不完全确定这会如何影响事情,除了内存清理所需的变量。

请注意,我使用 PrettyKit 库,所以我的单元格是 PrettyTableViewCells。

崩溃报告:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Incident Identifier: A58F4152-0593-481D-8269-1A8115739349
CrashReporter Key:   2dc2c9f2bdbc6370165a53719bc7610fcbe36ddd
Hardware Model:      iPhone4,1
Process:         Yoga [50409]
Path:            /var/mobile/Applications/DEE2950F-4629-43D4-BA6E-349E4119094F/Yoga.app/Yoga
Identifier:      Yoga
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-04-23 10:41:02.152 +1000
OS Version:      iOS 6.1.3 (10B329)
Report Version:  104

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  0

Application Specific Information:
Yoga [50409] has active assertions beyond permitted time:
{(
    <BKProcessAssertion: 0x1f590b90> identifier: Suspending process: Yoga[50409] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:26 preventSuspend  preventThrottleDownCPU  preventThrottleDownUI
)}

Elapsed total CPU time (seconds): 8.260 (user 8.260, system 0.000), 67% CPU
Elapsed application CPU time (seconds): 5.953, 49% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   CoreFoundation                  0x313a21fa -[__NSSetM addObject:] + 326
1   Foundation                      0x31dfd1f8 __44-[NSISEngine fixupIntegralizationViolations]_block_invoke_0 + 868
2   Foundation                      0x31dfe9a4 -[NSISEngine withoutOptimizingAtEndRunBlockWithAutomaticOptimizationDisabled:] + 104
3   Foundation                      0x31dfce8a -[NSISEngine fixupIntegralizationViolations] + 90
4   Foundation                      0x31dfe766 -[NSISEngine optimize] + 74
5   Foundation                      0x31dffc4e -[NSISEngine constraintDidChangeSuchThatMarker:shouldBeReplacedByMarkerPlusDelta:] + 82
6   Foundation                      0x31dffcc8 -[NSISEngine tryToChangeConstraintSuchThatMarker:isReplacedByMarkerPlusDelta:undoHandler:] + 56
7   Foundation                      0x31e0564e -[NSLayoutConstraint _tryToChangeContainerGeometryWithUndoHandler:] + 266
8   Foundation                      0x31e059d6 -[NSLayoutConstraint _setSymbolicConstant:constant:] + 382
9   UIKit                           0x3368e14a -[UIView(UIConstraintBasedLayout) _autoresizingConstraints_frameDidChange] + 342
10  UIKit                           0x33253c32 -[UIView(Geometry) setFrame:] + 558
11  UIKit                           0x3329ec4c -[UITableViewCellContentView setFrame:] + 48
12  Foundation                      0x31d03ff2 _NSSetRectValueAndNotify + 106
13  UIKit                           0x332a18cc -[UITableViewCellLayoutManager layoutSubviewsOfCell:] + 2188
14  UIKit                           0x332a0968 -[UITableViewCell layoutSubviews] + 56
15  UIKit                           0x332557fe -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
16  QuartzCore                      0x32fffd86 -[CALayer layoutSublayers] + 210
17  QuartzCore                      0x32fff924 CA::Layer::layout_if_needed(CA::Transaction*) + 456
18  QuartzCore                      0x33000858 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12
19  QuartzCore                      0x3300023e CA::Context::commit_transaction(CA::Transaction*) + 234
20  QuartzCore                      0x3300004c CA::Transaction::commit() + 312
21  QuartzCore                      0x32fffeac CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
22  CoreFoundation                  0x3141f6ca __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
23  CoreFoundation                  0x3141d9bc __CFRunLoopDoObservers + 272
24  CoreFoundation                  0x3141dd12 __CFRunLoopRun + 738
25  CoreFoundation                  0x31390eb8 CFRunLoopRunSpecific + 352
26  CoreFoundation                  0x31390d44 CFRunLoopRunInMode + 100
27  GraphicsServices                0x34f692e6 GSEventRunModal + 70
28  UIKit                           0x332a62fc UIApplicationMain + 1116
29  Yoga                            0x000af198 0xae000 + 4504
30  libdyld.dylib                   0x395a9b1c start + 0

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x39660648 kevent64 + 24
1   libdispatch.dylib               0x39590974 _dispatch_mgr_invoke + 792
2   libdispatch.dylib               0x39590654 _dispatch_mgr_thread$VARIANT$mp + 32

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x396700fc __psynch_mutexwait + 24
1   libsystem_c.dylib               0x395b9124 pthread_mutex_lock + 388
2   WebCore                         0x373a6418 _WebTryThreadLock(bool) + 184
3   WebCore                         0x373a634a WebRunLoopLock(__CFRunLoopObserver*, unsigned long, void*) + 42
4   CoreFoundation                  0x3141f6ca __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
5   CoreFoundation                  0x3141d9bc __CFRunLoopDoObservers + 272
6   CoreFoundation                  0x3141dde8 __CFRunLoopRun + 952
7   CoreFoundation                  0x31390eb8 CFRunLoopRunSpecific + 352
8   CoreFoundation                  0x31390d44 CFRunLoopRunInMode + 100
9   WebCore                         0x373a4500 RunWebThread(void*) + 440
10  libsystem_c.dylib               0x395c930e _pthread_start + 306
11  libsystem_c.dylib               0x395c91d4 thread_start + 4

Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib          0x3965feb4 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x39660048 mach_msg + 36
2   CoreFoundation                  0x3141f040 __CFRunLoopServiceMachPort + 124
3   CoreFoundation                  0x3141dd9e __CFRunLoopRun + 878
4   CoreFoundation                  0x31390eb8 CFRunLoopRunSpecific + 352
5   CoreFoundation                  0x31390d44 CFRunLoopRunInMode + 100
6   Foundation                      0x31cdd3d0 +[NSURLConnection(Loader) _resourceLoadLoop:] + 304
7   Foundation                      0x31d60e80 __NSThread__main__ + 968
8   libsystem_c.dylib               0x395c930e _pthread_start + 306
9   libsystem_c.dylib               0x395c91d4 thread_start + 4

Thread 4 name:  com.apple.CFSocket.private
Thread 4:
0   libsystem_kernel.dylib          0x39670594 __select + 20
1   CoreFoundation                  0x314231f2 __CFSocketManager + 674
2   libsystem_c.dylib               0x395c930e _pthread_start + 306
3   libsystem_c.dylib               0x395c91d4 thread_start + 4

Thread 5 name:  JavaScriptCore::BlockFree
Thread 5:
0   libsystem_kernel.dylib          0x3967008c __psynch_cvwait + 24
1   libsystem_c.dylib               0x395c1d2a _pthread_cond_wait + 642
2   libsystem_c.dylib               0x395c1aa0 pthread_cond_timedwait + 40
3   JavaScriptCore                  0x3535fc70 WTF::ThreadCondition::timedWait(WTF::Mutex&, double) + 104
4   JavaScriptCore                  0x35471552 JSC::BlockAllocator::blockFreeingThreadMain() + 78
5   JavaScriptCore                  0x35483fa8 WTF::wtfThreadEntryPoint(void*) + 12
6   libsystem_c.dylib               0x395c930e _pthread_start + 306
7   libsystem_c.dylib               0x395c91d4 thread_start + 4

Thread 6 name:  JavaScriptCore::Marking
Thread 6:
0   libsystem_kernel.dylib          0x3967008c __psynch_cvwait + 24
1   libsystem_c.dylib               0x395c1d2a _pthread_cond_wait + 642
2   libsystem_c.dylib               0x395cbf14 pthread_cond_wait + 36
3   JavaScriptCore                  0x35404f3c JSC::SlotVisitor::drainFromShared(JSC::SlotVisitor::SharedDrainMode) + 144
4   JavaScriptCore                  0x35404e7c JSC::MarkStackThreadSharedData::markingThreadMain() + 140
5   JavaScriptCore                  0x35483fa8 WTF::wtfThreadEntryPoint(void*) + 12
6   libsystem_c.dylib               0x395c930e _pthread_start + 306
7   libsystem_c.dylib               0x395c91d4 thread_start + 4

Thread 7 name:  WebCore: CFNetwork Loader
Thread 7:
0   libsystem_kernel.dylib          0x3965feb4 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x39660048 mach_msg + 36
2   CoreFoundation                  0x3141f040 __CFRunLoopServiceMachPort + 124
3   CoreFoundation                  0x3141dd9e __CFRunLoopRun + 878
4   CoreFoundation                  0x31390eb8 CFRunLoopRunSpecific + 352
5   CoreFoundation                  0x31390d44 CFRunLoopRunInMode + 100
6   WebCore                         0x3743ed02 WebCore::runLoaderThread(void*) + 138
7   JavaScriptCore                  0x35483fa8 WTF::wtfThreadEntryPoint(void*) + 12
8   libsystem_c.dylib               0x395c930e _pthread_start + 306
9   libsystem_c.dylib               0x395c91d4 thread_start + 4

Unknown thread crashed with unknown flavor: 5, state_count: 1

代码:

我已通过日志记录确定代码在冻结之前成功通过了我的 didSelectRowAtIndexPath 和 prepareForSegue 方法。因此我相信这与表格单元格的构造有关吗?还是一些我没有解决的内存问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"logPracticeDetails" sender:indexPath];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *indexPath = sender;

    if ([segue.identifier isEqualToString:@"logPracticeDetails"])
    {
        YLLogPracticeViewController *controller = segue.destinationViewController;
        controller.logPractice = [self.logEntry.logEntryPractices objectAtIndex:indexPath.row];
    }
}

非常感谢任何帮助。


对于仍然有类似问题的任何人,我发现原因是我的项目中的 AutoLayout。

我所要做的只是为我的 UIViewController 停用自动布局,然后冻结就停止了。


1
2
[self performSegueWithIdentifier:@"logPracticeDetails" sender:indexPath];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];

这样说

1
2
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier:@"logPracticeDetails" sender:indexPath];

先取消选择,然后转到下一页