App termination after applying constraints programmatically - ios

I have two views, establish the subviews, create a constraint, then apply it. myView and topview are two UIViews under 'myOverylingView'
import UIKit
class ViewController: UIViewController {
#IBOutlet var myOverlyingView: UIView!
#IBOutlet weak var myView: UIView!
var x : Int = 500;
override func viewDidLoad() {
super.viewDidLoad()
var topview = NSKeyedUnarchiver.unarchiveObjectWithData(NSKeyedArchiver.archivedDataWithRootObject(self.myView)) as? UIView
myOverlyingView.addSubview(topview!)
topview!.backgroundColor = UIColor.blueColor()
var myConstraint : NSLayoutConstraint = NSLayoutConstraint(item: topview!, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.myView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
topview!.addConstraint(myConstraint)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
After applying the constraint I get a termination error as follows.
2015-06-03 14:03:00.716 threadingTest1[30147:4645926] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fb43bb00500 UIView:0x7fb43bb00800.centerX == UIView:0x7fb43941ff30.centerX>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
2015-06-03 14:03:00.720 threadingTest1[30147:4645926] View hierarchy unprepared for constraint.
Constraint: <NSLayoutConstraint:0x7fb43bb00500 UIView:0x7fb43bb00800.centerX == UIView:0x7fb43941ff30.centerX>
Container hierarchy:
<UIView: 0x7fb43bb00800; frame = (150 100; 300 65); autoresize = RM+BM; layer = <CALayer: 0x7fb43bb00000>>
View not found in container hierarchy: <UIView: 0x7fb43941ff30; frame = (150 100; 300 65); autoresize = RM+BM; layer = <CALayer: 0x7fb43941ef20>>
That view's superview: <UIView: 0x7fb43941fc20; frame = (0 0; 375 667); autoresize = RM+BM; layer = <CALayer: 0x7fb43941f260>>
2015-06-03 14:03:00.725 threadingTest1[30147:4645926] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:<NSLayoutConstraint:0x7fb43bb00500 UIView:0x7fb43bb00800.centerX == UIView:0x7fb43941ff30.centerX> view:<UIView: 0x7fb43bb00800; frame = (150 100; 300 65); autoresize = RM+BM; layer = <CALayer: 0x7fb43bb00000>>'
*** First throw call stack:
(
0 CoreFoundation 0x0000000100c69c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001027d4bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000100c69b9d +[NSException raise:format:] + 205
3 Foundation 0x0000000101083479 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 187
4 UIKit 0x0000000101b83a34 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
5 Foundation 0x00000001010911be -[NSISEngine withBehaviors:performModifications:] + 155
6 UIKit 0x0000000101b8383a __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
7 UIKit 0x0000000101b8364d -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
8 UIKit 0x0000000101b83933 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
9 Foundation 0x00000001010911be -[NSISEngine withBehaviors:performModifications:] + 155
10 UIKit 0x0000000101b8383a __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
11 UIKit 0x0000000101b8364d -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
12 UIKit 0x0000000101b832de -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] + 404
13 UIKit 0x0000000101b83de1 -[UIView(AdditionalLayoutSupport) _layoutEngineCreateIfNecessary] + 53
14 UIKit 0x0000000101b787e7 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 156
15 UIKit 0x0000000101b78b74 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30
16 UIKit 0x0000000101b78c9c -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243
17 threadingTest1 0x0000000100a6e625 _TFC14threadingTest114ViewController11viewDidLoadfS0_FT_T_ + 1637
18 threadingTest1 0x0000000100a6e6d2 _TToFC14threadingTest114ViewController11viewDidLoadfS0_FT_T_ + 34
19 UIKit 0x0000000101639210 -[UIViewController loadViewIfRequired] + 738
20 UIKit 0x000000010163940e -[UIViewController view] + 27
21 UIKit 0x00000001015542c9 -[UIWindow addRootViewControllerViewIfPossible] + 58
22 UIKit 0x000000010155468f -[UIWindow _setHidden:forced:] + 247
23 UIKit 0x0000000101560e21 -[UIWindow makeKeyAndVisible] + 42
24 UIKit 0x0000000101504457 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
25 UIKit 0x00000001015071de -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
26 UIKit 0x00000001015060d5 -[UIApplication workspaceDidEndTransaction:] + 179
27 FrontBoardServices 0x00000001042e45e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
28 CoreFoundation 0x0000000100b9d41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
29 CoreFoundation 0x0000000100b93165 __CFRunLoopDoBlocks + 341
30 CoreFoundation 0x0000000100b92f25 __CFRunLoopRun + 2389
31 CoreFoundation 0x0000000100b92366 CFRunLoopRunSpecific + 470
32 UIKit 0x0000000101505b42 -[UIApplication _run] + 413
33 UIKit 0x0000000101508900 UIApplicationMain + 1282
34 threadingTest1 0x0000000100a75057 main + 135
35 libdyld.dylib 0x0000000102f2c145 start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This first portion of the error message stands out to me as it asks if I am trying to constrain something outside the subtree of the view.
I am trying to follow this understanding of the view hierarchy here, Mac Developer Library, though I may be interpreting it incorrectly.
Any help would be appreciated.

This makes no sense. You say this:
#IBOutlet weak var myView: UIView!
But you also say this:
myOverlyingView.addSubview(self.myView)
If you are expecting myView to arrive as an outlet, then it must be in the interface already. So how can you then add it as a subview to anything?
If it is not arriving as an outlet, then it is nil, and that explains why you can't set up a constraint to it.
Either way, those two lines are incoherent in relation to one another.

Related

Eureka MultivaluedSection Add NSRangeException

Any kind of special setup needed to make MultivaluedSection Add functionality to work in Eureka?
I have copied code from Example project into mine and instead of rows being added I get an exception. Funny thing is that in Example project everything seems to work fine, that makes me thinking that I need some kind of additional setup, maybe?
Exception:
'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:usingPresentationValues:]: row (1) beyond bounds (1) for section (1).
uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:usingPresentationValues:]: row (1) beyond bounds (1) for section (1).'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c9ab1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010c30df41 objc_exception_throw + 48
2 CoreFoundation 0x000000010ca1fb95 +[NSException raise:format:] + 197
3 UIKit 0x0000000109bc8d76 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:usingPresentationValues:] + 1861
4 UIKit 0x0000000109bc9b8f -[UITableView _scrollToRowAtIndexPath:atScrollPosition:animated:usingPresentationValues:] + 146
5 UIKit 0x0000000109bc9a11 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 123
6 Eureka 0x0000000107b7558c _T06Eureka18FormViewControllerC05tableC0ySo07UITableC0C_SC0fC16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttF + 2780
7 Eureka 0x0000000107b75ba7 _T06Eureka18FormViewControllerC05tableC0ySo07UITableC0C_SC0fC16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttFTo + 119
8 UIKit 0x0000000109bee33e -[UITableView _didInsertRowForTableCell:] + 122
9 UIKit 0x0000000109ec6bee -[UITableViewCell editControlWasClicked:] + 180
10 UIKit 0x0000000109a949bd -[UIApplication sendAction:to:from:forEvent:] + 83
11 UIKit 0x0000000109c0b183 -[UIControl sendAction:to:forEvent:] + 67
12 UIKit 0x0000000109c0b4a0 -[UIControl _sendActionsForEvents:withEvent:] + 450
13 UIKit 0x0000000109c0b614 -[UIControl _sendActionsForEvents:withEvent:] + 822
14 UIKit 0x0000000109c0a3cd -[UIControl touchesEnded:withEvent:] + 618
15 UIKit 0x000000010a071a88 _UIGestureEnvironmentSortAndSendDelayedTouches + 5560
16 UIKit 0x000000010a06b93e _UIGestureEnvironmentUpdate + 1483
17 UIKit 0x000000010a06b327 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
18 UIKit 0x000000010a06a3d3 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 288
19 UIKit 0x0000000109b0a45c -[UIWindow sendEvent:] + 4102
20 UIKit 0x0000000109aaf802 -[UIApplication sendEvent:] + 352
21 UIKit 0x000000010a3e1a50 __dispatchPreprocessedEventFromEventQueue + 2809
22 UIKit 0x000000010a3e45b7 __handleEventQueueInternal + 5957
23 CoreFoundation 0x000000010c94e2b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010c9edd31 __CFRunLoopDoSource0 + 81
25 CoreFoundation 0x000000010c932c19 __CFRunLoopDoSources0 + 185
26 CoreFoundation 0x000000010c9321ff __CFRunLoopRun + 1279
27 CoreFoundation 0x000000010c931a89 CFRunLoopRunSpecific + 409
28 GraphicsServices 0x0000000110c5a9c6 GSEventRunModal + 62
29 UIKit 0x0000000109a92d30 UIApplicationMain + 159
Solved.
My custom ViewController was overriding override func viewWillAppear(_ animated: Bool), but I forgot to call super.viewWillAppear().
Turns out that was critical for Eureka to work properly
Related to OP, I too had same error. In my case it was caused because I was embedding the FormViewController() incorrectly inside another view controller.
My solution was to add it as childViewController (see Eureka Issue 1045). In short, childViewControllers receive appearance & rotation events from parent VC (viewWillAppear etc) What does addChildViewController actually do?.
My working Sample code (swift 4.2):
class MyViewController: UIViewController {
var tempForm:FormViewController!
override func viewDidLoad() {
super.viewDidLoad()
tempTemp = FormViewController()
self.addChild(tempForm)
self.setupTempFormSections()
}
private func setupTempFormSections(){
tempForm.form +++ Section(...)
}
...
}

is there a way to get a UIView's frame (create in storyboard) in code

I createa a UIView in the storyboard, and want to add some inner shadow to this view. I also created an IBoutlet to this view. Is there any way to get view's frame?
#IBOutlet weak var display: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
print(display.frame.height)
}
error
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Calculator.ViewController 0x7fba77608cd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key screen.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d7a2b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109cd5141 objc_exception_throw + 48
2 CoreFoundation 0x000000010d7a2a59 -[NSException raise] + 9
3 Foundation 0x00000001097eb00b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010b09e994 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010b30ba09 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010d748e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x000000010b30a3bf -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010b0a4fc3 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010b0a58d9 -[UIViewController loadView] + 177
10 UIKit 0x000000010b0a5c0a -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010b0a645a -[UIViewController view] + 27
12 UIKit 0x000000010af6e98a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x000000010af6f070 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010af81ebe -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010aefb37f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x000000010af015e4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x000000010aefe7f3 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x0000000111b715f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x0000000111b7146d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x0000000111b717f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x000000010d748c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010d72e0cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x000000010d72d5ff __CFRunLoopRun + 911
24 CoreFoundation 0x000000010d72d016 CFRunLoopRunSpecific + 406
25 UIKit 0x000000010aefd08f -[UIApplication _run] + 468
26 UIKit 0x000000010af03134 UIApplicationMain + 159
27 Calculator 0x00000001096fa327 main + 55
28 libdyld.dylib 0x000000010e74265d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
help appreciated
You are saying its a view but you have drawn an IBOutlet of UILabel.
Also yourView.frame will definitely give you the frame.
Also try deleting the previous outlet and redraw it.
You have added an outlet for a UILabel, but stil the same there to get the frame display.frame. Add an outlet to your view instead if you want that and then just view.frame.
It dosen't matter if it´s a view created in your storyboard or programmatically, you can always get the frame by:
view.frame
But if you specially want the frame that you have created in your Storyboard then you need to create an IBOutlet.

Unrecognized Selector Instance When Performing Segue

When performing programatically performing a segue, the segue does work and the intended storyboard opens, but terminates immediately afterwards. The view controller/storyboard does work and shouldn't have any errors in the code as I've tested it individually, so I'm not entirely sure as to why it terminates. Any help would be appreciated.
2017-05-01 20:22:59.358605 FInal Project[15659:499662] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/student/Library/Developer/CoreSimulator/Devices/265EA47F-07A6-47C7-A6B4-5E62D37E72BA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-05-01 20:22:59.376075 FInal Project[15659:499662] [MC] Reading from private effective user settings.
in
2017-05-01 20:23:48.095 FInal Project[15659:499662] <UILayoutContainerView: 0x7fdae3c082f0; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000242be0>; layer = <CALayer: 0x60000003ea40>>'s window is not equal to <UINavigationController: 0x7fdae40aee00>'s view's window!
2017-05-01 20:23:48.715 FInal Project[15659:499662] -[FInal_Project.User_Info NameInputEditingDidEnd:]: unrecognized selector sent to instance 0x7fdae3c11d40
2017-05-01 20:23:48.721 FInal Project[15659:499662] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FInal_Project.User_Info NameInputEditingDidEnd:]: unrecognized selector sent to instance 0x7fdae3c11d40'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101fc3d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000101a2521e objc_exception_throw + 48
2 CoreFoundation 0x0000000102033f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000101f49005 ___forwarding___ + 1013
4 CoreFoundation 0x0000000101f48b88 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001030cb8bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000103251c38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000103251f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000103bdbc20 -[UITextField _resignFirstResponder] + 313
9 UIKit 0x00000001032e1778 -[UIResponder _finishResignFirstResponder] + 286
10 UIKit 0x0000000103bdba0e -[UITextField _finishResignFirstResponder] + 49
11 UIKit 0x00000001032e1827 -[UIResponder resignFirstResponder] + 140
12 UIKit 0x0000000103bdb8dd -[UITextField resignFirstResponder] + 136
13 UIKit 0x000000010317802f -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 167
14 UIKit 0x00000001031786b8 __UIViewWillBeRemovedFromSuperview + 76
15 UIKit 0x000000010317846a -[UIView(Hierarchy) removeFromSuperview] + 95
16 UIKit 0x000000010324d451 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.629 + 704
17 UIKit 0x0000000103246fba -[UIPresentationController transitionDidFinish:] + 111
18 UIKit 0x000000010345ef83 -[_UICurrentContextPresentationController transitionDidFinish:] + 42
19 UIKit 0x000000010324aef0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
20 UIKit 0x0000000103c0c56c -[_UIViewControllerTransitionContext completeTransition:] + 102
21 UIKit 0x0000000103243ddc -[UITransitionView notifyDidCompleteTransition:] + 251
22 UIKit 0x0000000103243aef -[UITransitionView _didCompleteTransition:] + 1539
23 UIKit 0x000000010324651c -[UITransitionView _transitionDidStop:finished:] + 104
24 UIKit 0x0000000103156bd5 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
25 UIKit 0x000000010315712a -[UIViewAnimationState animationDidStop:finished:] + 136
26 QuartzCore 0x0000000108526648 _ZN2CA5Layer23run_animation_callbacksEPv + 316
27 libdispatch.dylib 0x0000000105e2e0cd _dispatch_client_callout + 8
28 libdispatch.dylib 0x0000000105e0e8a4 _dispatch_main_queue_callback_4CF + 406
29 CoreFoundation 0x0000000101f87e49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
30 CoreFoundation 0x0000000101f4d37d __CFRunLoopRun + 2205
31 CoreFoundation 0x0000000101f4c884 CFRunLoopRunSpecific + 420
32 GraphicsServices 0x0000000107d38a6f GSEventRunModal + 161
33 UIKit 0x00000001030c9c68 UIApplicationMain + 159
34 FInal Project 0x00000001013fb65f main + 111
35 libdyld.dylib 0x0000000105e7a68d start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The issue (discovered in the comments above) was that there was an action in the storyboard that was no longer hooked up to an action in code.
If anyone else in the future has a similar problem, look through the outlets menu for an outlet or action with the name provided in the console output. In this case, the action was named NameInputEditingDidEnd.
To expand on Nathan's answer, instead of randomly looking around, just cmd+shift+f the name of the outlet, in this case NameInputEditingDidEnd, and xcode will output the storyboard with the dangling outlet for you and center you to it.

UITableView causing crash on iOS7?

This crash is reported by a crash reporting tool, It only happens on iOS7 and I am not able to reproduce.
It seems like something calls scrollView:contentSizeForZoomScale:withProposedSize, the cell contains 2 buttons that resize depending on the data passed to it (no scrollViews, and nowhere a delegate for any UIScrollView is getting set).
Any thoughts on what causes the scrollView delegate method to get called on the cell?
Fatal Exception: NSInvalidArgumentException
-[ProfileContactUserCell scrollView:contentSizeForZoomScale:withProposedSize:]: unrecognized selector sent to instance 0x127592a20
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x000000018169b100 __exceptionPreprocess
1 libobjc.A.dylib 0x000000018dba41fc objc_exception_throw
2 CoreFoundation 0x000000018169fdb4 __methodDescriptionForSelector
3 CoreFoundation 0x000000018169dae0 ___forwarding___
4 CoreFoundation 0x00000001815bd78c _CF_forwarding_prep_0
5 UIKit 0x0000000184680d38 -[UIScrollView setFrame:]
6 UIKit 0x000000018467b12c -[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:]
7 UIKit 0x000000018476ad20 -[UIScrollView _resizeWithOldSuperviewSize:]
8 CoreFoundation 0x00000001815ad1dc __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke
9 CoreFoundation 0x00000001815ad0a8 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]
10 UIKit 0x000000018466a9f8 -[UIView(Geometry) resizeSubviewsWithOldSize:]
11 UIKit 0x000000018465b9f8 -[UIView(Geometry) setFrame:]
12 UIKit 0x00000001847400d8 -[UITableViewCell setFrame:]
13 UIKit 0x00000001847adf74 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke
14 UIKit 0x0000000184672de0 +[UIView(Animation) performWithoutAnimation:]
15 UIKit 0x00000001847adcc8 -[UITableView _configureCellForDisplay:forIndexPath:]
16 UIKit 0x00000001847ac90c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]
17 UIKit 0x000000018474ae4c -[UITableView _updateVisibleCellsNow:]
18 UIKit 0x000000018473d8a4 -[UITableView _visibleCells]
19 UIKit 0x000000018473d768 -[UITableView setSeparatorStyle:]
20 Company 0x00000001000ae7ac -[ProfileViewController viewDidLoad] (ProfileViewController.m:104)
21 UIKit 0x0000000184664658 -[UIViewController loadViewIfRequired]
22 UIKit 0x00000001846643dc -[UIViewController view]
23 UIKit 0x0000000184811850 -[UINavigationController _startCustomTransition:]
24 UIKit 0x000000018471bf3c -[UINavigationController _startDeferredTransitionIfNeeded:]
25 UIKit 0x000000018471bd0c -[UINavigationController __viewWillLayoutSubviews]
26 UIKit 0x000000018471bc8c -[UILayoutContainerView layoutSubviews]
27 UIKit 0x000000018465efe0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
28 QuartzCore 0x0000000184250258 -[CALayer layoutSublayers]
29 QuartzCore 0x000000018424ae20 CA::Layer::layout_if_needed(CA::Transaction*)
30 QuartzCore 0x000000018424acd8 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
31 QuartzCore 0x000000018424a560 CA::Context::commit_transaction(CA::Transaction*)
32 QuartzCore 0x000000018424a304 CA::Transaction::commit()
33 UIKit 0x0000000184663154 _UIApplicationHandleEventQueue
34 CoreFoundation 0x000000018165b7f4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
35 CoreFoundation 0x000000018165ab50 __CFRunLoopDoSources0
36 CoreFoundation 0x0000000181658de8 __CFRunLoopRun
37 CoreFoundation 0x0000000181599dd0 CFRunLoopRunSpecific
38 GraphicsServices 0x0000000187281c0c GSEventRunModal
39 UIKit 0x00000001846cafc4 UIApplicationMain
40 Company 0x0000000100072c1c main (main.m:13)
41 libdyld.dylib 0x000000018e197aa0 start
EDIT:
Implemented that method, and it looks like it's being called by:
<UITableViewCellScrollView: 0x78e39ee0; frame = (0 0; 320 44); autoresize = W+H; gestureRecognizers = <NSArray: 0x78eafc10>; layer = <CALayer: 0x78e354a0>; contentOffset: {0, 0}>
On iOS7 apple made changes to the view hierarchy of a UITableViewCell.
In iOS 7 the contntView is embedded in a UIScrollView, and the scrollView on some situations (I haven't figured out when) calls that method on the cell.
The fix was to implement the following method and return the poposedSize. This fix is only needed on iOS7. The viewHierarchy on iOS8+ has been changed to the way it was on iOS6. (No more UIScrollView is used in a tableViewCell hierarchy)
- (CGSize)scrollView:(id)arg1 contentSizeForZoomScale:(float)arg2 withProposedSize:(CGSize)arg3 {
return arg3;
}

Adding constraints programmatically to IB Scene

I'm trying to add a subview and some constraints to a scene, which is build using the interface builder.
The subview gets added correctly, but when I try to add the constraints the app crashes with the following error, which implies that I've got the view hierarchy mixed up. However I'm can't find my error.
Shopigator[14377:635114] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fafab4bb660 THSegmentedControl:0x7fafaf03a6e0.centerX == UISearchBar:0x7fafaf0334b0.centerX>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
2015-03-13 11:51:12.004 Shopigator[14377:635114] View hierarchy unprepared for constraint.
Constraint: <NSLayoutConstraint:0x7fafab4bb660 THSegmentedControl:0x7fafaf03a6e0.centerX == UISearchBar:0x7fafaf0334b0.centerX>
Container hierarchy:
<UIView: 0x7fafaf037d70; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fafab424a00>>
| <_UILayoutGuide: 0x7fafaf037e40; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fafa97e4710>>
| <_UILayoutGuide: 0x7fafaf037540; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fafaf0ed980>>
| <UIView: 0x7fafaf035e40; frame = (0 0; 500 50); layer = <CALayer: 0x7fafaf0a9be0>>
| <THSegmentedControl: 0x7fafaf03a6e0; baseClass = UIControl; frame = (34 297; 332 29); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7fafaf0398d0>>
View not found in container hierarchy: <UISearchBar: 0x7fafaf0334b0; frame = (0 0; 320 44); text = ''; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fafb10ad1f0>; layer = <CALayer: 0x7fafab44ed10>>
That view's superview: NO SUPERVIEW
2015-03-13 11:51:12.060 Shopigator[14377:635114] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:<NSLayoutConstraint:0x7fafab4bb660 THSegmentedControl:0x7fafaf03a6e0.centerX == UISearchBar:0x7fafaf0334b0.centerX> view:<UIView: 0x7fafaf037d70; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fafab424a00>>'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a2df35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001086c6bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000108a2de6d +[NSException raise:format:] + 205
3 Foundation 0x0000000107f6e0f9 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 187
4 UIKit 0x0000000109b77de5 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
5 Foundation 0x0000000107f7bd6e -[NSISEngine withBehaviors:performModifications:] + 155
6 UIKit 0x0000000109b77beb __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
7 UIKit 0x0000000109b779fe -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
8 UIKit 0x0000000109b77671 -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] + 404
9 UIKit 0x0000000109b78191 -[UIView(AdditionalLayoutSupport) _layoutEngineCreateIfNecessary] + 53
10 UIKit 0x0000000109b6cb0a -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 156
11 UIKit 0x0000000109b6cea4 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30
12 UIKit 0x0000000109b6cfcc -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243
13 Shopigator 0x0000000107507617 _TFC10Shopigator20FilterViewController11viewDidLoadfS0_FT_T_ + 9623
14 Shopigator 0x0000000107508d92 _TToFC10Shopigator20FilterViewController11viewDidLoadfS0_FT_T_ + 34
15 UIKit 0x0000000109617a90 -[UIViewController loadViewIfRequired] + 738
16 UIKit 0x0000000109617c8e -[UIViewController view] + 27
17 UIKit 0x0000000109bb941e -[_UIFullscreenPresentationController _setPresentedViewController:] + 65
18 UIKit 0x00000001095f3429 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 105
19 UIKit 0x0000000109623a41 -[UIViewController _presentViewController:withAnimationController:completion:] + 1746
20 UIKit 0x0000000109625d81 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
21 UIKit 0x0000000109625ca5 -[UIViewController presentViewController:animated:completion:] + 229
22 UIKit 0x00000001094f38be -[UIApplication sendAction:to:from:forEvent:] + 75
23 UIKit 0x00000001095fa410 -[UIControl _sendActionsForEvents:withEvent:] + 467
24 UIKit 0x00000001095f97df -[UIControl touchesEnded:withEvent:] + 522
25 UIKit 0x0000000109539308 -[UIWindow _sendTouchesForEvent:] + 735
26 UIKit 0x0000000109539c33 -[UIWindow sendEvent:] + 683
27 UIKit 0x00000001095069b1 -[UIApplication sendEvent:] + 246
28 UIKit 0x0000000109513a7d _UIApplicationHandleEventFromQueueEvent + 17370
29 UIKit 0x00000001094ef103 _UIApplicationHandleEventQueue + 1961
30 CoreFoundation 0x0000000108963551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
31 CoreFoundation 0x000000010895941d __CFRunLoopDoSources0 + 269
32 CoreFoundation 0x0000000108958a54 __CFRunLoopRun + 868
33 CoreFoundation 0x0000000108958486 CFRunLoopRunSpecific + 470
34 GraphicsServices 0x000000010b2849f0 GSEventRunModal + 161
35 UIKit 0x00000001094f2420 UIApplicationMain + 1282
36 Shopigator 0x000000010748081e top_level_code + 78
37 Shopigator 0x000000010748085a main + 42
38 libdyld.dylib 0x000000010b7a8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Relevant parts of my ViewController
#IBOutlet weak var searchBar: UISearchBar!
#IBOutlet weak var radiusSlider: LoagarithmicSlider!
var priceClassSelector: THSegmentedControl?
override func viewDidLoad() {
super.viewDidLoad()
var pCFrame = CGRectMake(34, 297, 332, 29)
self.priceClassSelector = THSegmentedControl(segments: SearchFilter.PRICE_CLASS_LABELS)
self.priceClassSelector!.frame = pCFrame
self.priceClassSelector?.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(self.priceClassSelector!)
self.view.addConstraint(NSLayoutConstraint(
item: self.priceClassSelector!,
attribute: NSLayoutAttribute.CenterX,
relatedBy: NSLayoutRelation.Equal,
toItem: self.searchBar,
attribute: NSLayoutAttribute.CenterX,
multiplier: 1.0,
constant: 0))
}
And the view hierarchy in IB

Resources