简体   繁体   English

iOS:在返回UITableViewCell时获得通知

[英]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.

相关问题 当UI更新时,IOS会收到通知。 - IOS get notified when UI updates. 如何获得UITableViewCell移动开始和结束的通知? - How to get notified of UITableViewCell move start and end? 当用户选择允许访问iOS中的Camera时收到通知 - Get notified when the user makes selection for allowing access to Camera in iOS Xamarin Forms iOS中的网络连接更改时如何获得通知 - How to get notified when network connection changes in Xamarin Forms iOS 如何在 iOS 收到新短信时收到通知 - How to get notified when new SMS is received in iOS 在iOS中连接或断开wifi时如何获取通知? - How to get notified when wifi gets connected or disconnected in iOS? 当 UIViewController 返回顶部时,iOS 中是否有委托函数来获得通知? - Is there a delegate function in iOS to get notified when a UIViewController is coming back to top? iOS - 如何在AFHTTPClient完成所有操作时收到通知 - iOS - How to get notified when AFHTTPClient is done with all operations 当用户允许iOS中的摄像头访问警报时如何获得通知? - How to get notified when user allows the camera access alert in iOS? 如何在iOS中卸载我们的应用程序时收到通知 - How to get notified when our app is uninstalled in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM