Scroll to bottom when keyboard appears causing crash - ios

I want to scroll my tableview to bottom when keyboard appears. But i am getting lot of crash reports from my users.
My code:
func keyboardWillShow(_ notification: Foundation.Notification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.2, animations: {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
})
let numberOfRows = tableView.numberOfRows(inSection: 0)
if numberOfRows != 0 {
do {
try tableView.scrollToRow(at: IndexPath(row: numberOfRows-1, section: 0), at: .bottom, animated: false)
}catch {
print("error")
}
}
}
Crash log:
Fatal Exception: NSRangeException
0 CoreFoundation 0x18f3bafe0 __exceptionPreprocess
1 libobjc.A.dylib 0x18de1c538 objc_exception_throw
2 CoreFoundation 0x18f299200 -[__NSArrayM removeObjectAtIndex:]
3 UIKit 0x195826f90 -[UITableView _existingCellForRowAtIndexPath:]
4 UIKit 0x195836a50 -[UITableView _heightForRowAtIndexPath:]
5 UIKit 0x1956291c0 -[UISectionRowData heightForRow:inSection:canGuess:]
6 UIKit 0x195628ebc -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:]
7 UIKit 0x19562c21c -[UITableView rectForRowAtIndexPath:]
8 UIKit 0x195704180 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]
9 UIKit 0x195703c84 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]
10 Ribony 0x1000a3044 ChatViewController.keyboardWillShow(Notification) -> () (ChatViewController.swift)
11 Ribony 0x1000a07d4 #objc ChatViewController.showConnectedLayout(Notification) -> ()
12 CoreFoundation 0x18f3555f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
13 CoreFoundation 0x18f354d08 _CFXRegistrationPost
14 CoreFoundation 0x18f354a84 ___CFXNotificationPost_block_invoke
15 CoreFoundation 0x18f3c37a8 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
16 CoreFoundation 0x18f29895c _CFXNotificationPost
17 Foundation 0x18fdaa930 -[NSNotificationCenter postNotificationName:object:userInfo:]
18 UIKit 0x195ed0190 -[UIInputWindowController postStartNotifications:withInfo:]
19 UIKit 0x195ed0edc __48-[UIInputWindowController viewDidLayoutSubviews]_block_invoke
20 UIKit 0x195ecdc04 -[UIInputWindowController performWithSafeTransitionFrames:]
21 UIKit 0x195ed098c -[UIInputWindowController viewDidLayoutSubviews]
22 UIKit 0x1954e90f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
23 QuartzCore 0x1926d9274 -[CALayer layoutSublayers]
24 QuartzCore 0x1926cdde8 CA::Layer::layout_if_needed(CA::Transaction*)
25 UIKit 0x1954fd814 -[UIView(Hierarchy) layoutBelowIfNeeded]
26 UIKit 0x195ecc4cc -[UIInputSetHostView layoutIfNeeded]
27 UIKit 0x195c79310 -[_UIRemoteKeyboards controllerDidLayoutSubviews:]
28 UIKit 0x195d49364 -[UICompatibilityInputViewController viewDidLayoutSubviews]
29 UIKit 0x1954e90f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
30 QuartzCore 0x1926d9274 -[CALayer layoutSublayers]
31 QuartzCore 0x1926cdde8 CA::Layer::layout_if_needed(CA::Transaction*)
32 UIKit 0x1954fd814 -[UIView(Hierarchy) layoutBelowIfNeeded]
33 UIKit 0x195ecc4cc -[UIInputSetHostView layoutIfNeeded]
34 UIKit 0x195ed4da0 -[UIInputWindowController _updateBackdropViews]
35 UIKit 0x195d4823c -[UICompatibilityInputViewController setInputMode:]
36 CoreFoundation 0x18f3555f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
37 CoreFoundation 0x18f354d08 _CFXRegistrationPost
38 CoreFoundation 0x18f354a84 ___CFXNotificationPost_block_invoke
39 CoreFoundation 0x18f3c37a8 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
40 CoreFoundation 0x18f29895c _CFXNotificationPost
41 Foundation 0x18fdaa930 -[NSNotificationCenter postNotificationName:object:userInfo:]
42 UIKit 0x195908be4 -[UIKeyboardImpl setKeyboardInputMode:userInitiated:updateIndicator:executionContext:]
43 UIKit 0x19590a388 -[UIKeyboardImpl setInputModeToNextInPreferredListWithExecutionContext:]
44 UIKit 0x1956aed88 -[UIKeyboardLayoutStar completeSendStringActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:]
45 UIKit 0x1956a1f18 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:]
46 UIKit 0x19592bbb8 __45-[UIKeyboardLayout touchUpTaskForTouchState:]_block_invoke
47 UIKit 0x195515e0c -[UIKeyboardTaskQueue continueExecutionOnMainThread]
48 UIKit 0x19592b868 -[UIKeyboardLayout _touchEndedProcessingForTouches:]
49 UIKit 0x195520390 -[UIWindow _sendTouchesForEvent:]
50 UIKit 0x19551b728 -[UIWindow sendEvent:]
51 UIKit 0x1954ec33c -[UIApplication sendEvent:]
52 UIKit 0x195ce6014 __dispatchPreprocessedEventFromEventQueue
53 UIKit 0x195ce0770 __handleEventQueue
54 UIKit 0x195ce0b9c __handleHIDEventFetcherDrain
55 CoreFoundation 0x18f36942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
56 CoreFoundation 0x18f368d9c __CFRunLoopDoSources0
57 CoreFoundation 0x18f3669a8 __CFRunLoopRun
58 CoreFoundation 0x18f296da4 CFRunLoopRunSpecific
59 GraphicsServices 0x190d00074 GSEventRunModal
60 UIKit 0x195551058 UIApplicationMain
61 Ribony 0x10003f11c main (AppDelegate.swift:15)
62 libdyld.dylib 0x18e2a559c start
How can i resolve this issue?

I am convinced problem lays here
UIView.animate(withDuration: 0.2, animations: {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
})
...
try tableView.scrollToRow(at: IndexPath(row: numberOfRows-1, section: 0), at: .bottom, animated: false)
You are reloading layout and trying to scroll in the very same moment, you should scroll afterwards or before. Might be I am not right, but this is usually the problem.

Related

What's the cause of crash "Crashed: com.apple.main-thread EXC_BREAKPOINT"

I'm getting this crash on crashlytics (fabric), but unable to reproduce it or understand its origin based on the traceback.
Crashed: com.apple.main-thread
0 MyApp 0x1001080a0 MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift:135)
1 MyApp 0x1001080d0 #objc MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift)
2 UIKit 0x18868bbf4 -[UIViewController _setViewAppearState:isAnimating:] + 632
3 UIKit 0x18868b964 -[UIViewController __viewWillAppear:] + 156
4 UIKit 0x1888101d4 -[UINavigationController _startCustomTransition:] + 1144
5 UIKit 0x18872ab78 -[UINavigationController _startDeferredTransitionIfNeeded:] + 676
6 UIKit 0x18872a7e0 -[UINavigationController __viewWillLayoutSubviews] + 64
7 UIKit 0x18872a744 -[UILayoutContainerView layoutSubviews] + 188
8 UIKit 0x18867107c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200
9 QuartzCore 0x185861274 -[CALayer layoutSublayers] + 148
10 QuartzCore 0x185855de8 CA::Layer::layout_if_needed(CA::Transaction*) + 292
11 QuartzCore 0x185855ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
12 QuartzCore 0x1857d134c CA::Context::commit_transaction(CA::Transaction*) + 252
13 QuartzCore 0x1857f83ac CA::Transaction::commit() + 504
14 UIKit 0x1888f2524 _UIApplicationFlushRunLoopCATransactionIfTooLate + 172
15 UIKit 0x188e689f8 __handleEventQueue + 4916
16 UIKit 0x188e68b9c __handleHIDEventFetcherDrain + 148
17 CoreFoundation 0x1824f142c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
18 CoreFoundation 0x1824f0d9c __CFRunLoopDoSources0 + 540
19 CoreFoundation 0x1824ee9a8 __CFRunLoopRun + 744
20 CoreFoundation 0x18241eda4 CFRunLoopRunSpecific + 424
21 GraphicsServices 0x183e88074 GSEventRunModal + 100
22 UIKit 0x1886d9058 UIApplicationMain + 208
23 MyApp 0x1009052fc main (AppDelegate.swift:16)
24 libdyld.dylib 0x18142d59c start + 4
The code in MyViewController:
#IBOutlet weak var someConstraint: NSLayoutConstraint!
#IBOutlet weak var button: UIButton!
let minHeight: CGFloat = 2.0
let cValue: CGFloat = 32.0
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let aValue = button.frame.origin.y - UIApplication.shared.statusBarFrame.height
let bValue = button.bounds.height + minHeight
someConstraint.constant = max(aValue - bValue, cValue) // --> Crash here, line 135
}
Update: SomeConstraint is not nil.

Too many crashes about scroll to bottom

I am getting too many crashes from my users for scroll to bottom. What can be cause to this problem?
I am scrolling to bottom my tableview when keyboard appears. And this causes to crash. My code:
func keyboardWillShow(notification: NSNotification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2) {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
}
let numberOfRows = tableView.numberOfRowsInSection(0)
if numberOfRows != 0 {
do {
try tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: numberOfRows-1, inSection: 0), atScrollPosition: .Bottom, animated: false) //This line is crashing
}catch {
print("error")
}
}
}
Crash log:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010013e018
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 Ribony 0x000000010013e018 specialized ChatViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell + 1904 (ChatViewController.swift:0)
1 Ribony 0x0000000100135890 #objc ChatViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell + 76 (ChatViewController.swift:0)
2 UIKit 0x000000018e315b58 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 716 (UITableView.m:10665)
3 UIKit 0x000000018e315e00 -[UITableView _createPreparedCellForRowAtIndexPath:willDisplay:] + 88 (UITableView.m:10717)
4 UIKit 0x000000018e31b4a8 -[UITableView _heightForRowAtIndexPath:] + 256 (UITableView.m:12615)
5 UIKit 0x000000018e1127c4 -[UISectionRowData heightForRow:inSection:canGuess:] + 280 (UITableViewRowData.m:288)
6 UIKit 0x000000018e4a413c -[UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:scrollPosition:] + 1484 (UITableViewRowData.m:2418)
7 UIKit 0x000000018e1ef4f8 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 1792 (UITableView.m:5544)
8 UIKit 0x000000018e1eecb0 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 52 (UITableView.m:5644)
9 Ribony 0x000000010013ed00 specialized ChatViewController.keyboardWillShow(NSNotification) -> () + 800 (ChatViewController.swift:550)
10 Ribony 0x0000000100136e98 #objc ChatViewController.keyboardWillShow(NSNotification) -> () + 56 (ChatViewController.swift:0)
11 CoreFoundation 0x00000001880b6b10 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:650)
12 CoreFoundation 0x00000001880b6214 _CFXRegistrationPost + 400 (CFNotificationCenter.c:164)
13 CoreFoundation 0x00000001880b5f90 ___CFXNotificationPost_block_invoke + 60 (CFNotificationCenter.c:1031)
14 CoreFoundation 0x0000000188125b8c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504 (CFXNotificationRegistrar.m:163)
15 CoreFoundation 0x0000000187ff7e64 _CFXNotificationPost + 376 (CFNotificationCenter.c:1028)
16 Foundation 0x0000000188b2ce0c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 (NSNotification.m:482)
17 UIKit 0x000000018e9a6b40 -[UIInputWindowController postStartNotifications:withInfo:] + 400 (UIInputWindowController.m:1375)
18 UIKit 0x000000018e9a8cf0 __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.907 + 388 (UIInputWindowController.m:1816)
19 UIKit 0x000000018e0080f0 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 636 (UIView.m:11811)
20 UIKit 0x000000018e0d952c +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 128 (UIView.m:11865)
21 UIKit 0x000000018e9a876c -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1368 (UIInputWindowController.m:1877)
22 UIKit 0x000000018e9af268 -[UIInputWindowController setInputViewSet:] + 1444 (UIInputWindowController.m:2923)
23 UIKit 0x000000018e9a7e38 -[UIInputWindowController performOperations:withAnimationStyle:] + 56 (UIInputWindowController.m:1674)
24 UIKit 0x000000018e099278 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1276 (UIPeripheralHost.m:4647)
25 UIKit 0x000000018dff8a78 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 80 (UIResponder.m:1107)
26 UIKit 0x000000018e056b4c -[UIResponder becomeFirstResponder] + 600 (UIResponder.m:272)
27 UIKit 0x000000018e056ebc -[UIView(Hierarchy) becomeFirstResponder] + 148 (UIView.m:9419)
28 UIKit 0x000000018e0d90b4 -[UITextField becomeFirstResponder] + 60 (UITextField.m:1396)
29 UIKit 0x000000018e180128 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 192 (UITextInteractionAssistant.m:1160)
30 UIKit 0x000000018e17f630 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 3024 (UITextInteractionAssistant.m:1770)
31 UIKit 0x000000018e59af80 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64 (UIGestureRecognizer.m:103)
32 UIKit 0x000000018e59e688 _UIGestureRecognizerSendTargetActions + 124 (UIGestureRecognizer.m:986)
33 UIKit 0x000000018e16573c _UIGestureRecognizerSendActions + 260 (UIGestureRecognizer.m:1020)
34 UIKit 0x000000018e0040f0 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 764 (UIGestureRecognizer.m:1067)
35 UIKit 0x000000018e58e680 _UIGestureEnvironmentUpdate + 1100 (UIGestureEnvironment.m:148)
36 UIKit 0x000000018e58e1e0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 408 (UIGestureEnvironment.m:1181)
37 UIKit 0x000000018e58d49c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 268 (UIGestureEnvironment.m:1090)
38 UIKit 0x000000018e00230c -[UIWindow sendEvent:] + 2960 (UIWindow.m:2289)
39 UIKit 0x000000018dfd2da0 -[UIApplication sendEvent:] + 340 (UIApplication.m:10729)
40 UIKit 0x000000018e7bc75c __dispatchPreprocessedEventFromEventQueue + 2736 (UIEventDispatcher.m:1430)
41 UIKit 0x000000018e7b6130 __handleEventQueue + 784 (UIEventDispatcher.m:1626)
42 CoreFoundation 0x00000001880cab5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1943)
43 CoreFoundation 0x00000001880ca4a4 __CFRunLoopDoSources0 + 524 (CFRunLoop.c:1989)
44 CoreFoundation 0x00000001880c80a4 __CFRunLoopRun + 804 (CFRunLoop.c:2821)
45 CoreFoundation 0x0000000187ff62b8 CFRunLoopRunSpecific + 444 (CFRunLoop.c:3113)
46 GraphicsServices 0x0000000189aaa198 GSEventRunModal + 180 (GSEvent.c:2245)
47 UIKit 0x000000018e03d7fc -[UIApplication _run] + 684 (UIApplication.m:2650)
48 UIKit 0x000000018e038534 UIApplicationMain + 208 (UIApplication.m:4092)
49 Ribony 0x00000001000ce070 main + 120 (AppDelegate.swift:15)
50 libdyld.dylib 0x0000000186fd95b8 start + 4
As you can see i am using this in a try catch block. It should not crash. How is this possible?
Try this code
func keyboardWillShow(notification: NSNotification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2) {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
}
tableViewScrollToBottom(true)
}
func tableViewScrollToBottom(animated: Bool) {
let delay = 0.2 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
let numberOfSections = self.tableView.numberOfSections()
let numberOfRows = self.tableView.numberOfRowsInSection(numberOfSections-1)
if numberOfRows > 0 {
let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))
self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
}
})
}

Click on button in table cell crash at IBAction ios

I am having three buttons in table view cell when click on button it is crashed strangely in line I am attaching code and crash report please suggest a solution.
Code for button click:
#IBAction func ibaReject(sender: UIButton) {
let notification = notifications[sender.tag]
let notificationHandler = NotificationHandlerFactory.getNotificationHandler(notification)
notificationHandler?.handleNegativeAction(notification,viewController: self)
}
Crash report from crashlytics:
Crashed: com.apple.main-thread
0 Quickride 0x1000c589c specialized NotificationViewController.ibaReject(UIButton) -> () (NotificationViewController.swift)
1 Quickride 0x1000c2d28 #objc NotificationViewController.ibaReject(UIButton) -> () (NotificationViewController.swift)
2 UIKit 0x18d31e7b0 -[UIApplication sendAction:to:from:forEvent:] + 96
3 UIKit 0x18d31e730 -[UIControl sendAction:to:forEvent:] + 80
4 UIKit 0x18d308be4 -[UIControl _sendActionsForEvents:withEvent:] + 452
5 UIKit 0x18d31e01c -[UIControl touchesEnded:withEvent:] + 584
6 UIKit 0x18d31db44 -[UIWindow _sendTouchesForEvent:] + 2484
7 UIKit 0x18d318d8c -[UIWindow sendEvent:] + 2988
8 UIKit 0x18d2e9858 -[UIApplication sendEvent:] + 340
9 UIKit 0x18dad6cb8 __dispatchPreprocessedEventFromEventQueue + 2736
10 UIKit 0x18dad0720 __handleEventQueue + 784
11 CoreFoundation 0x18744e278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
12 CoreFoundation 0x18744dbc0 __CFRunLoopDoSources0 + 524
13 CoreFoundation 0x18744b7c0 __CFRunLoopRun + 804
14 CoreFoundation 0x18737a048 CFRunLoopRunSpecific + 444
15 GraphicsServices 0x188dfd198 GSEventRunModal + 180
16 UIKit 0x18d354628 -[UIApplication _run] + 684
17 UIKit 0x18d34f360 UIApplicationMain + 208
18 Quickride 0x1002d4018 main (AppDelegate.swift:23)
19 libdispatch.dylib 0x18635c5b8 (Missing)

Understanding an iOS stacktrace

I'm kinda new to debugging iOS exceptions.
On the fabric.io site I can see that a few users has seen this crash.
Can anyone please help me get started?
Crashed: com.apple.main-thread
0 gismoapp 0x114760 specialized WeekPlanController.scrollViewWillBeginDragging(UIScrollView) -> () (WeekPlanController.swift:428)
1 gismoapp 0x1144a0 specialized WeekPlanController.scrollViewWillBeginDragging(UIScrollView) -> () (WeekPlanController.swift:428)
2 gismoapp 0x11102c #objc WeekPlanController.scrollViewWillBeginDragging(UIScrollView) -> () (WeekPlanController.swift)
3 UIKit 0x261b4609 -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging] + 232
4 UIKit 0x261b3a9d -[UIScrollView _updatePanGesture] + 284
5 UIKit 0x265685db _UIGestureRecognizerSendTargetActions + 142
6 UIKit 0x261a08e3 _UIGestureRecognizerSendActions + 170
7 UIKit 0x26030d15 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1004
8 UIKit 0x2656993f ___UIGestureRecognizerUpdate_block_invoke898 + 62
9 UIKit 0x25ff1587 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 298
10 UIKit 0x25fedaf9 _UIGestureRecognizerUpdate + 2920
11 UIKit 0x2602ec01 -[UIWindow _sendGesturesForEvent:] + 904
12 UIKit 0x2602e3b3 -[UIWindow sendEvent:] + 622
13 UIKit 0x25ffec85 -[UIApplication sendEvent:] + 204
14 UIKit 0x25ffd229 _UIApplicationHandleEventQueue + 5016
15 CoreFoundation 0x219efa67 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
16 CoreFoundation 0x219ef657 __CFRunLoopDoSources0 + 454
17 CoreFoundation 0x219ed9bf __CFRunLoopRun + 806
18 CoreFoundation 0x2193c289 CFRunLoopRunSpecific + 516
19 CoreFoundation 0x2193c07d CFRunLoopRunInMode + 108
20 GraphicsServices 0x22f58af9 GSEventRunModal + 160
21 UIKit 0x260672c5 UIApplicationMain + 144
22 gismoapp 0xb7084 main (AppDelegate.swift:14)
23 libdispatch.dylib 0x215e8873 (Missing)
The code in question:
func scrollViewWillBeginDragging(scrollView: UIScrollView){
if let lastSyncDate = Settings.lastSyncedDate {
// This is line 428 in WeekPlanController
self.refreshControl.attributedTitle = NSAttributedString(string: "last synced \(lastSyncDate.relativeTimeToString()) ago")
}
}

SIGTRAP on set background color

I have a swift view controller that is a subclass of JSQMessagesViewController and I'm seeing a weird SIGTRAP in viewDidLoad. Namely it occasionally happens when I try to set the background color. It happens sporadically so I'm not sure what might be happening.
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor()
}
Here's the crash log:
Thread 0 Crashed:
0 MyApp 0x00000001000ecc74 MyApp.MessageDetailViewController.viewDidLoad ()() (MessageDetailViewController.swift:130)
1 MyApp 0x00000001000ecc94 #objc MyApp.MessageDetailViewController.viewDidLoad ()() (MessageDetailViewController.swift:0)
2 UIKit 0x0000000187834b40 -[UIViewController loadViewIfRequired] + 992
3 UIKit 0x0000000187834744 -[UIViewController view] + 24
4 UIKit 0x00000001878f4f88 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 308
5 UIKit 0x00000001878f4238 -[UINavigationController _startTransition:fromViewController:toViewController:] + 140
6 UIKit 0x00000001878f3ddc -[UINavigationController _startDeferredTransitionIfNeeded:] + 864
7 UIKit 0x00000001878f3a04 -[UINavigationController __viewWillLayoutSubviews] + 56
8 UIKit 0x00000001878f396c -[UILayoutContainerView layoutSubviews] + 204
9 UIKit 0x00000001878300e4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 652
10 QuartzCore 0x00000001851d6a28 -[CALayer layoutSublayers] + 144
11 QuartzCore 0x00000001851d1634 CA::Layer::layout_if_needed(CA::Transaction*) + 288
12 QuartzCore 0x00000001851d14f4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 28
13 QuartzCore 0x00000001851d0b24 CA::Context::commit_transaction(CA::Transaction*) + 248
14 QuartzCore 0x00000001851d086c CA::Transaction::commit() + 508
15 QuartzCore 0x00000001851c9dd8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 76
16 CoreFoundation 0x00000001826a07b0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
17 CoreFoundation 0x000000018269e554 __CFRunLoopDoObservers + 368
18 CoreFoundation 0x000000018269e984 __CFRunLoopRun + 924
19 CoreFoundation 0x00000001825c8d10 CFRunLoopRunSpecific + 380
20 GraphicsServices 0x0000000183eb0088 GSEventRunModal + 176
21 UIKit 0x000000018789df70 UIApplicationMain + 200
22 MyApp 0x00000001000286b4 main (main.m:16)
23 ??? 0x00000001821668b8 0x0 + 0
The controller is presented modally in a navigation controller but then can transition to being pushed onto the nav stack (similar to composing a message in the stock sms app). Maybe it is possible that the lack of animation is causing an issue?
func controllerDidSendMessageInThread(controller: MessageDetailViewController, thread: Thread) {
self.dismissViewControllerAnimated(false, completion: nil)
let detail = MessageDetailViewController(thread: thread)
self.navigationController?.pushViewController(detail, animated: animated)
}

Resources