ios - 如何覆盖 reloadRowsAtIndexPath?
<p><p>我正在尝试覆盖 tableView 单元格的方法 <code>reloadRowAtIndexPath</code>。 </p>
<p>我想和你重写 <code>cellForRowAtIndexPath</code> 时一样:</p>
<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
if(isUserTalking(indexPath))
{
return userMessageCell(indexPath)
}
else
{
if(isNotUserFirstMessage(indexPath))
{
return notUserFirstMessageCell(indexPath)
}
else
{
return notUserNotFirstMessageCell(indexPath)
}
}
}
</code></pre>
<p>这样:</p>
<pre><code>func tableView(tableView: UITableView, reloadRowsAtIndexPaths indexPath: NSIndexPath) -> UITableViewCell
{
print("job")
if(isNotUserFirstMessage(indexPath))
{
return notUserFirstMessageCell(indexPath, showImage: false)
}
else
{
return notUserNotFirstMessageCell(indexPath, showImage: false)
}
}
</code></pre>
<p>但是当我使用 <code>self.myTable.reloadRowsAtIndexPath</code> 它从不调用覆盖版本。 </p>
<p>你知道怎么解决吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><code>reloadRowsAtIndexPaths</code> 并不是为了这个。您可能想使用 <code>
tableView(_:willDisplayCell:forRowAtIndexPath:)</code> 代替。例如:</p>
<pre><code>func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
print("job")
if isNotUserFirstMessage(indexPath) {
configureNotUserFirstMessageCell(cell, showImage: false)
} else {
configureNotUserNotFirstMessageCell(cell, showImage: false)
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何覆盖 reloadRowsAtIndexPath?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37886353/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37886353/
</a>
</p>
页:
[1]