Re: NSSegmentedControl & NSSegmentStyleSeparated & autolayout
Re: NSSegmentedControl & NSSegmentStyleSeparated & autolayout
- Subject: Re: NSSegmentedControl & NSSegmentStyleSeparated & autolayout
- From: Jacek Oleksy <email@hidden>
- Date: Thu, 27 Aug 2015 09:12:24 +0200
It is in the documentation, see
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSSegmentedControl_Class/#//apple_ref/c/tdef/NSSegmentStyle
This is the list for 10.10 (copied from NSSegmentedControl.h):
typedef NS_ENUM(NSInteger, NSSegmentStyle) {
NSSegmentStyleAutomatic = 0,
NSSegmentStyleRounded = 1,
NSSegmentStyleRoundRect = 3,
NSSegmentStyleTexturedSquare = 4,
NSSegmentStyleSmallSquare = 6,
NSSegmentStyleSeparated NS_ENUM_AVAILABLE_MAC(10_10) = 8,
NSSegmentStyleTexturedRounded NS_ENUM_AVAILABLE_MAC(10_5) = 2,
NSSegmentStyleCapsule NS_ENUM_AVAILABLE_MAC(10_5) = 5
} NS_ENUM_AVAILABLE_MAC(10_5);
I am running the code on OSX 10.10.5, and the control looks ok (i.e.
it *does* have the style NSSegmentStyleSeparated). It seems to me like
the old check was left in NSUserInterfaceTheme .m (like maybe case
missing in a switch?).
Jacek
On Wed, Aug 26, 2015 at 6:20 PM, Thaddeus Cooper
<email@hidden> wrote:
> I just checked the documentation and did not see NSSegmentStyleSeparated in the list of NSSegmentStyle enums. Here is the list:
>
> enum {
> NSSegmentStyleAutomatic = 0,
> NSSegmentStyleRounded = 1,
> NSSegmentStyleTexturedRounded = 2,
> NSSegmentStyleRoundRect = 3,
> NSSegmentStyleTexturedSquare = 4,
> NSSegmentStyleCapsule = 5,
> NSSegmentStyleSmallSquare = 6,
> NSSegmentStyleSeparated = 8,
> };
>
> I would be willing to bet that the method that is asserting is checking to make sure that the segment style is one of the nine that are defined in the list of enums. The fact that it only does that check when using auto layout seems like a bug to me. I’d file a bug with Apple.
>
> Thaddeus O. Cooper
> (email@hidden)
>
>
>
>> On Aug 26, 2015, at 6:38 AM, Jacek Oleksy <email@hidden> wrote:
>>
>> Nope, I am still getting the exception.
>>
>> J.
>>
>> On Wed, Aug 26, 2015 at 3:31 PM, Ken Thomases <email@hidden> wrote:
>>> On Aug 26, 2015, at 7:04 AM, Jacek Oleksy <email@hidden> wrote:
>>>
>>>> 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?
>>>
>>> This is a shot in the dark, but: does it help to initialize with -initWithFrame: instead of -init? (You can pass NSZeroRect.)
>>>
>>> Regards,
>>> Ken
>>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden