[英]iOS: Get notified when UITableViewCell is returned
I have a UITableView with multiple cells showing information about places including a small compass arrow pointing towards those places. 我有一个带有多个单元格的UITableView,其中显示了有关地点的信息,包括指向这些地点的小罗盘箭头。
For the arrow I have a function which calculates the bearing using the current location and heading and then it iterates through every visible cell of the TableView and rotates the arrows. 对于箭头,我有一个函数,该函数使用当前位置和方向来计算方位,然后遍历TableView的每个可见单元并旋转箭头。 This function is called whenever the position or heading of the device is changed.
只要更改设备的位置或方向,就会调用此函数。
Now I would like to call the function also whenever a new cell is returned and also would like to pass the index of the cell so only this arrow will be calculated for the first time. 现在,我想在返回新单元格时也调用该函数,并且还希望传递该单元格的索引,因此将仅第一次计算该箭头。
If I use - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
the cell is not returned yet... 如果我使用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
该单元格尚未返回...
I could use the viewDidScroll
function and work with the first or last visible cell depending on the scroll direction but then the function would also be called if no new cell get's visible. 我可以使用
viewDidScroll
函数并根据滚动方向使用第一个或最后一个可见单元格,但是如果没有新的单元格可见,那么该函数也将被调用。
Is there any chance to get notified when a cell gets returned and which cell it is? 返回一个单元格以及它是哪个单元格时,是否有机会得到通知?
You could use the tableView:willDisplayCell:forRowAtIndexPath:
delegate method instead. 您可以改用
tableView:willDisplayCell:forRowAtIndexPath:
委托方法。 From the docs: "A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed". 在文档中:“表视图在它使用单元格绘制行之前将消息发送给它的委托人,从而允许委托人在显示该对象之前对其进行自定义”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.