Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My custom view, a multi-selection enabled action sheet, crashes whenever it's size is changed and then added as a subview, or whenever it's resized after it's been added. My errors say that my constraints are conflicting, but I can't understand why. I've been using a similar pattern for all my other custom views (view = [Bundle loadNibNamed], view.frame = presenter.view.frame+modifiers) and they all work fine, with their constraints too.

"<NSAutoresizingMaskLayoutConstraint:0xc588920 h=--- v=--- V:[UIWindow:0xc18d290(480)]>",
"<NSAutoresizingMaskLayoutConstraint:0xc129980 h=-&- v=-&- UIView:0xd8c6210.height == SWRevealView:0xd8c5f40.height>",
"<NSAutoresizingMaskLayoutConstraint:0xd8ccb80 h=-&- v=-&- SWRevealView:0xd8c5f40.height == UIWindow:0xc18d290.height>",
"<NSAutoresizingMaskLayoutConstraint:0xc5aa660 h=-&- v=-&- UILayoutContainerView:0xc5a3d90.height == UIView:0xd8c6210.height>",
"<NSLayoutConstraint:0xda96c20 V:[UIButton:0xda99260(45)]>",
"<NSLayoutConstraint:0xda89310 V:|-(427)-[UITableView:0xe855c00]   (Names: '|':MultiSelectionSheet:0xdaac360'Select Filters' )>",
"<NSLayoutConstraint:0xda8c1d0 V:[UITableView:0xe855c00]-(1)-[UIButton:0xda99260]>",
"<NSLayoutConstraint:0xda6d520 V:[UIButton:0xda99260]-(NSSpace(20))-|   (Names: '|':MultiSelectionSheet:0xdaac360'Select Filters' )>",
"<NSAutoresizingMaskLayoutConstraint:0xc5962c0 h=-&- v=-&- MultiSelectionSheet:0xdaac360'Select Filters'.height == UILayoutContainerView:0xc5a3d90.height>"

constraints layout

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
    <deployment defaultVersion="1536" identifier="iOS"/>
    <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
</dependencies>
<objects>
    <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
    <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
    <view contentMode="scaleToFill" id="1" customClass="MultiSelectionSheet">
        <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
        <subviews>
            <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" style="plain" separatorStyle="default" allowsMultipleSelection="YES" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="mXD-gg-Pfl">
                <rect key="frame" x="5" y="20" width="310" height="482"/>
                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                <inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
            </tableView>
            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="emp-R8-XZ7">
                <rect key="frame" x="5" y="503" width="310" height="45"/>
                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                <color key="backgroundColor" red="0.27450980390000002" green="0.76470588240000004" blue="0.83529411760000005" alpha="1" colorSpace="calibratedRGB"/>
                <constraints>
                    <constraint firstAttribute="height" constant="45" id="Ykt-VQ-0SN"/>
                </constraints>
                <state key="normal" title="DONE">
                    <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                    <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                </state>
                <connections>
                    <action selector="dismissTable:" destination="1" eventType="touchUpInside" id="b33-Bh-apy"/>
                </connections>
            </button>
        </subviews>
        <color key="backgroundColor" white="0.26408531021897808" alpha="1" colorSpace="calibratedWhite"/>
        <constraints>
            <constraint firstItem="mXD-gg-Pfl" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="2zC-KQ-ZOt"/>
            <constraint firstItem="emp-R8-XZ7" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="5" id="6gg-Py-tQZ"/>
            <constraint firstItem="emp-R8-XZ7" firstAttribute="trailing" secondItem="mXD-gg-Pfl" secondAttribute="trailing" id="9cH-nC-BFj"/>
            <constraint firstItem="emp-R8-XZ7" firstAttribute="top" secondItem="mXD-gg-Pfl" secondAttribute="bottom" constant="1" id="MFF-2J-4nH"/>
            <constraint firstAttribute="trailing" secondItem="emp-R8-XZ7" secondAttribute="trailing" constant="5" id="OxD-y5-2uC"/>
            <constraint firstAttribute="bottom" secondItem="emp-R8-XZ7" secondAttribute="bottom" constant="20" symbolic="YES" id="cnS-12-qe0"/>
            <constraint firstItem="mXD-gg-Pfl" firstAttribute="leading" secondItem="emp-R8-XZ7" secondAttribute="leading" id="kWm-ho-P3w"/>
        </constraints>
        <simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
        <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
        <connections>
            <outlet property="dismissButton" destination="emp-R8-XZ7" id="Nwx-Xh-wGZ"/>
            <outlet property="sheetTable" destination="mXD-gg-Pfl" id="REB-gn-MlB"/>
            <outlet property="spaceAboveTable" destination="2zC-KQ-ZOt" id="uAY-xN-L78"/>
        </connections>
    </view>
</objects>

setting self.translatesAutoresizingMaskToConstrainsts = NO will allow the view to be drawn, but with dubious sizes and inaccurate frame sizes. Moreover, while set to NO, setting a static instead of dynamic height on the tableview will give more layout conflicts

share|improve this question
    
Can you attach .xib file? –  Sergey Demchenko Feb 3 at 16:12
    
Added the sheet xib as xml - the presenting view is a Storyboard UINavigationController –  mcornell Feb 3 at 16:27
1  
turn off autoresizingMask. In code you go myView.translatesAutoresizingMaskIntoConstraints = NO;, I'm sure there tick box for it on the view in the storyboard too. –  BooRanger Feb 3 at 16:33
    
while that does allow the view to be draw, it's then stretched out of shape. it collapses the whole table and shrinks the button to fit it's text, and the view floats somewhere around 40px down. Despite this, frame is still reading as 0x0,320x480 –  mcornell Feb 3 at 17:03
    
I was able to solve the squashing by only disabling translatesAutoresizing on subviews, not the entire view –  mcornell Feb 3 at 18:02
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.