Hi All,
I want to set NSSegmentStyleSeparated on my NSSegmentedControl
(managed by autolayout). However, when I create constraints for the
parent view, I get an exception:

Assertion failure in -[NSSegmentedControl ns_widgetType],
/SourceCache/AppKit/AppKit-1348.17/Layout.subproj/NSUserInterfaceTheme.m:398

An uncaught exception was raised
What kind of segmented control are we!

Example code:

(in WindowController)
- (void)windowDidLoad {
    [super windowDidLoad];
    NSSegmentedControl* segmentedControl = [[NSSegmentedControl alloc] init];
    [segmentedControl setSegmentCount:2];
    [segmentedControl setTranslatesAutoresizingMaskIntoConstraints:NO];
    segmentedControl.segmentStyle = NSSegmentStyleSeparated;
    [self.window.contentView addSubview:segmentedControl];
    NSString* constraint = @"|-[segmentedControl]-|";
    NSDictionary* views = NSDictionaryOfVariableBindings(segmentedControl);
    NSArray* constraints = [NSLayoutConstraint
                            constraintsWithVisualFormat:constraint
                            options:NSLayoutFormatDirectionLeadingToTrailing
                            metrics:nil
                            views:views];
    [self.window.contentView addConstraints:constraints];
}

The exception is raised in "addConstraints:".
Everything is fine if I do not change segmentStyle. It also works fine
if I change segment style *after* adding constraints, but then I get
the exception e.g. when dragging window to external display.

Any ideas?

Thanks for any help.

Jacek





And a stack trace:

TestSegmented[24775:165858] *** Assertion failure in
-[NSSegmentedControl ns_widgetType],
/SourceCache/AppKit/AppKit-1348.17/Layout.subproj/NSUserInterfaceTheme.m:398
TestSegmented[24775:165858] An uncaught exception was raised
TestSegmented[24775:165858] What kind of segmented control are we!
TestSegmented[24775:165858] (
0   CoreFoundation                      0x00007fff8bb8103c
__exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff89fec76e
objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8bb80e1a
+[NSException raise:format:arguments:] + 106
3   Foundation                          0x00007fff9700d99b
-[NSAssertionHandler
handleFailureInMethod:object:file:lineNumber:description:] + 195
4   AppKit                              0x00007fff9377be8c
-[NSSegmentedControl(NSIBSegmentedControlIntegration) ns_widgetType] +
198
5   AppKit                              0x00007fff935fabca
-[NSAquaUserInterfaceTheme _ruleForView:comparedToContainer:withEdge:]
+ 40
6   AppKit                              0x00007fff935f97bf
-[NSAquaUserInterfaceTheme
resolvedValue:forSymbolicConstant:inConstraint:containerView:] + 527
7   AppKit                              0x00007fff935f944b
-[NSLayoutConstraint(NSSymbolicConstantResolution)
defaultResolvedValue:forSymbolicConstant:error:] + 77
8   Foundation                          0x00007fff96faf969
-[NSLayoutConstraint _effectiveConstant:error:] + 105
9   Foundation                          0x00007fff96faf867
-[NSLayoutConstraint constant] + 52
10  Foundation                          0x00007fff96faea45
-[NSLayoutConstraint _lowerIntoExpression:reportingConstantIsRounded:]
+ 197
11  Foundation                          0x00007fff96fa2df6
-[NSLayoutConstraint
_addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:]
+ 95
12  AppKit                              0x00007fff935be49c
-[NSView(NSConstraintBasedLayout)
_layoutEngine_didAddLayoutConstraint:integralizationAdjustment:mutuallyExclusiveConstraints:]
+ 89
13  AppKit                              0x00007fff935be1eb
-[NSView(NSConstraintBasedLayout)
_tryToAddConstraint:integralizationAdjustment:mutuallyExclusiveConstraints:]
+ 299
14  AppKit                              0x00007fff935bdf77
__50-[NSView(NSConstraintBasedLayout) addConstraints:]_block_invoke +
188
15  AppKit                              0x00007fff934afc6c
-[NSView(NSConstraintBasedLayout) addConstraints:] + 279
16  TestSegmented                       0x0000000100001209
-[TestWindowController windowDidLoad] + 521
17  AppKit                              0x00007fff93608857
-[NSWindowController _windowDidLoad] + 586
18  CoreFoundation                      0x00007fff8ba8dbdf -[NSSet
makeObjectsPerformSelector:] + 223
19  AppKit                              0x00007fff9346800b
-[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] +
1166
20  AppKit                              0x00007fff9364290e -[NSNib
_instantiateNibWithExternalNameTable:options:] + 677
21  AppKit                              0x00007fff9364255e -[NSNib
_instantiateWithOwner:options:topLevelObjects:] + 143
22  AppKit                              0x00007fff93b8c53c
-[NSStoryboard instantiateControllerWithIdentifier:] + 181
23  AppKit                              0x00007fff9343ee64
NSApplicationMain + 840
24  TestSegmented                       0x00000001000012a2 main + 34
25  libdyld.dylib                       0x00007fff926b45c9 start + 1
)
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to