Skip to content

Commit

Permalink
添加第11篇【11.UITableView显示异常】
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed Sep 30, 2015
1 parent 8527372 commit 3d17939
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8121.17" systemVersion="15A178w" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -12,7 +12,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015年 itcast. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015年 微博@iOS程序犭袁. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.17" systemVersion="15A178w" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="lGW-Ou-SFc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="lGW-Ou-SFc">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +20,7 @@
<rect key="frame" x="0.0" y="22" width="600" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="XMq-4H-If0" id="3ZB-IX-KCp">
<rect key="frame" x="0.0" y="0.0" width="600" height="80"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="79"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5Sd-Vr-3Tf">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

@interface CYLNewsCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleView;
@property (weak, nonatomic) IBOutlet UILabel *summaryView;
@property (weak, nonatomic) IBOutlet UILabel *sitenameView;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@property (weak, nonatomic) IBOutlet UILabel *addtimeView;
@property (nonatomic, weak) IBOutlet UILabel *titleView;
@property (nonatomic, weak) IBOutlet UILabel *summaryView;
@property (nonatomic, weak) IBOutlet UILabel *sitenameView;
@property (nonatomic, weak) IBOutlet UIImageView *imgView;
@property (nonatomic, weak) IBOutlet UILabel *addtimeView;

@end

Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,55 @@ if ([currentLanguage hasPrefix:@"zh-Hans"])
疏漏之处,可前往阅读下[这个网站](http://asciiwwdc.com),这里有每年 WWDC 演讲的英文记录。
## 11.UITableView显示异常
原本在 Xcode6 上完好的项目,在 Xcode7 上一编译, `tableView` 出了两个问题 :
1. 代码创建的 `tableView` 无法隐藏 cell 分割线
2. `reloadData` 刷新失效;
### 代码创建的 `tableView` 无法隐藏 cell 分割线
iOS9 里面用到 tableView 突然跑出来了很多 cell 的分割线, 但是在用xib创建的 tableview,就不存在这个问题
解决方法是将设置分割线隐藏的方法 `self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;` 写在 `-layoutSubviews` 中:
```Objective-C
-(void)layoutSubviews{
[super layoutSubviews];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
```

也有人发现另一种方法,就是每次 reloadData 之前都进行一次设置:设置分割线隐藏,这样也可以解决:



```Objective-C
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView reloadData]
```

虽然也可以解决但是不推荐,这样写会给其他人造成困扰:不知所云。


### `reloadData` 刷新失效

现象: `[tableView reloadData]` 无效,有一行 cell 明明改变了但是刷新不出来。


感觉可能是这个方法和某种新加的特性冲突了,猜测可能是 `reloadData` 的操作被推迟到下一个 `RunLoop` 执行最终失效。

解决的方法是,注释 `[tableView reloadData]` ,改用局部刷新:

```Objective-C
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
```
这两个推测均属 Xcode7 的bug,将来 Apple 肯定会修复。
----------
Expand Down

0 comments on commit 3d17939

Please sign in to comment.