2017-02-02 137 views
0

面前我这里有一个奇怪的问题:网格显示在UITableViewCell中

Screenshot

我把UITableView的分离粉红色。正如你所看到的,在我的单元格的中间和末尾显示了一些行,但是有一个偏移量。当我滚动时它不会移动,所以我将它称为一个显示在我的单元格前面的网格。 我在这里面临的大问题是,它只显示在iPhone7模拟器(IOS 10)和更少(7s不显示此网格)。

你们对于为什么以及如何解决这个问题有什么想法吗?

如果你需要一些代码,告诉我,我会编辑我的文章。

谢谢!

这里是厦门国际银行:

<!--Articles--> 
     <scene sceneID="j0Y-qF-3lq"> 
      <objects> 
       <viewController id="6B8-Tk-xPz" userLabel="Articles" customClass="HeadController" customModule="E_R" sceneMemberID="viewController"> 
        <layoutGuides> 
         <viewControllerLayoutGuide type="top" id="H0o-ZU-FUz"/> 
         <viewControllerLayoutGuide type="bottom" id="DVT-NA-hNg"/> 
        </layoutGuides> 
        <view key="view" contentMode="scaleToFill" id="Qib-nc-8lK" customClass="UITableView"> 
         <rect key="frame" x="0.0" y="64" width="375" height="554"/> 
         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/> 
         <subviews> 
          <tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="90" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="oLy-kw-Uc2"> 
           <rect key="frame" x="0.0" y="0.0" width="375" height="554"/> 
           <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 
           <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 
           <color key="separatorColor" red="1" green="0.0" blue="0.95666110710516339" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> 
           <prototypes> 
            <tableViewCell opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ArticleTableViewCell" rowHeight="90" id="owe-aQ-qV4" customClass="ArticleTableViewCell" customModule="E_R"> 
             <rect key="frame" x="0.0" y="28" width="375" height="90"/> 
             <autoresizingMask key="autoresizingMask"/> 
             <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="owe-aQ-qV4" id="k3G-5w-mGo"> 
              <rect key="frame" x="0.0" y="0.0" width="375" height="89"/> 
              <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/> 
              <subviews> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" lineBreakMode="wordWrap" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VV9-uR-YRk"> 
                <rect key="frame" x="7" y="0.0" width="271" height="54"/> 
                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMaxY="YES"/> 
                <fontDescription key="fontDescription" name=".SFNSText" family=".SF NS Text" pointSize="13"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="T9Y-oH-4IA"> 
                <rect key="frame" x="7" y="57" width="268" height="34"/> 
                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/> 
                <fontDescription key="fontDescription" name=".SFNSText" family=".SF NS Text" pointSize="11"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z8M-gG-zVc"> 
                <rect key="frame" x="283" y="0.0" width="88" height="88"/> 
                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" heightSizable="YES"/> 
               </imageView> 
              </subviews> 
             </tableViewCellContentView> 
             <accessibility key="accessibilityConfiguration" identifier="ArticleTableViewCell"> 
              <bool key="isElement" value="NO"/> 
             </accessibility> 
             <gestureRecognizers/> 
             <connections> 
              <outlet property="previewImage" destination="Z8M-gG-zVc" id="J2R-HU-hYb"/> 
              <outlet property="subTitleLabel" destination="T9Y-oH-4IA" id="RuM-IV-kza"/> 
              <outlet property="titleLabel" destination="VV9-uR-YRk" id="9v5-6F-3lA"/> 
              <segue destination="BTc-SH-fsG" kind="show" identifier="ShowDetail" id="SZH-pm-QeE"/> 
             </connections> 
            </tableViewCell> 
           </prototypes> 
          </tableView> 
         </subviews> 
         <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 
        </view> 
        <extendedEdge key="edgesForExtendedLayout"/> 
        <navigationItem key="navigationItem" id="mnh-mw-Uiz"> 
         <segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="fill" contentVerticalAlignment="fill" segmentControlStyle="bar" selectedSegmentIndex="0" id="ghy-sl-9Yp"> 
          <rect key="frame" x="92" y="7" width="191" height="30"/> 
          <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
          <segments> 
           <segment title="A la une"/> 
           <segment title="Tous"/> 
          </segments> 
          <connections> 
           <action selector="SwitchList:" destination="6B8-Tk-xPz" eventType="valueChanged" id="a4M-GY-kSb"/> 
          </connections> 
         </segmentedControl> 
        </navigationItem> 
        <connections> 
         <outlet property="ArticlesList" destination="oLy-kw-Uc2" id="qXj-r7-lJg"/> 
         <outlet property="SegmentedArticles" destination="ghy-sl-9Yp" id="oTe-Vh-Kns"/> 
        </connections> 
       </viewController> 
       <placeholder placeholderIdentifier="IBFirstResponder" id="l57-G8-yDO" userLabel="First Responder" sceneMemberID="firstResponder"/> 
      </objects> 
      <point key="canvasLocation" x="237.59999999999999" y="425.93703148425789"/> 
     </scene> 

而且图像单元格原型:

Image cell prototype

+0

显示您的'prototype-cell'图像。 –

+0

在这里发布你的xib – iProgrammer

+0

看我的编辑。这个可以吗 ? –

回答

0

好的我有答案。很简单 !我有一个TableViewController,其中包括一个TableView。问题是我在TableViewController中包含了另一个TableView!这就是为什么我在我的第二个TableView前面有一种“网格”。

+0

我如何了解故事板中视图的层次结构。这些愚蠢的错误无法在这个社区得到解决。您应该完全调试,然后寻求帮助。无论如何,如果你有解决方案,我会很高兴快乐编码:) – iProgrammer

0

我觉得你的表视图的rowHeight是老丁的默认值。在viewDidLoad方法 试试这个代码:

override func viewDidLoad() { 
    tableView.estimatedRowHeight = 150.0 
    tableView.rowHeight = UITableViewAutomaticDimension 
    tableView.tableFooterView = UIView() 
} 

而且隐藏的tableView默认分隔符(如果已经添加它作为一个自定义的线,否则没有必要)

Like this

希望这将解决这个问题。

UPDATE

如果你不知道如何添加布局constarints和您的tableView只有一种类型的细胞,那么你可以设置rowHeight的故事板中也。选择您的viewController中的tableView并转到属性检查

添加截图:

设置所需rowHeight的这里。它可能会解决您的问题。

Row height

+0

Nop它不起作用...而且,布局不再好。 –

+0

您需要设置约束。它肯定会解决你的问题 – iProgrammer

+0

我没有一个。你的意思是对表格视图或单元格的约束? (我是IOS新手,很快) –