0
我有一个UITableViewController,并在控制器我有以下代码:的UITableView不更新在插入/滚动
// Update the table view
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:([self.transcripts count] - 1) inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// Scroll to the bottom so we focus on the latest transcript
NSUInteger numberOfRows = [self.tableView numberOfRowsInSection:0];
if (numberOfRows) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:(numberOfRows - 1) inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
我遇到的问题是,UITableView的永远不会更新。我已经证实我的成绩单数组越来越大,并且cellForRowAtIndexPath:
被调用。我很难过。我错过了什么?
编辑:这是我的IB tableView定义,如果有帮助。
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="MXJ-GP-L47">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="separatorColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="sectionIndexTrackingBackgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="MessageCell" id="sdU-aF-ZZy">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="sdU-aF-ZZy" id="7IE-xs-uAL">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="ImageCell" id="Lac-k8-MMs">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Lac-k8-MMs" id="IVD-DR-azV">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="ProgressCell" id="efc-wO-XPu">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="efc-wO-XPu" id="7j1-RG-rHz">
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Eyi-tC-JyD" id="AM2-Xx-Xsd"/>
<outlet property="delegate" destination="Eyi-tC-JyD" id="Tkb-ac-NHB"/>
</connections>
</tableView>
我试过了。这没有什么区别。我以后手动滚动时甚至不会看到行。 – 2014-10-08 14:06:18
尝试删除一个动画,或者插入用于滚动的动画的动画,这两个动画可能会发生干扰。但是你必须调用tableview的开始/结束更新。 – 2014-10-08 14:18:01
同样的结果,有和没有beginUpdates/endUpdates。如果有帮助,我将我的IB tableView定义添加到问题中。 – 2014-10-08 14:24:23