简体   繁体   English

iOS-UITableViewCell是否从superView中删除?

[英]iOS - UITableViewCell being removed from superView?

I have a UITableViewCell with textfileds, as soon as the cell is no longer visible on the screen I need to dismiss the keyboard. 我有一个带有textfileds的UITableViewCell,一旦该单元格在屏幕上不再可见,我就需要关闭键盘。 Is there a simple way to be notified when a cell is being removed from the tableView (is no longer visible)? 当从tableView中删除一个单元格(不再可见)时,是否有一种简单的通知方法?

I tried the following in my Cell Class, and it did not get called. 我在Cell Class中尝试了以下方法,但没有得到调用。

- (void)removedFromSuperView
{

}

Cells get reused. 细胞得到重用。 As a cell scrolls off one end of the screen it gets reused at the other end. 当单元格滚动离开屏幕的一端时,它将在另一端重新使用。

Why do you need to dismiss a keyboard when the row goes off the screen? 当行离开屏幕时,为什么需要关闭键盘? What if the user quickly scrolls the row back onto the screen? 如果用户快速将行滚动回到屏幕上怎么办? If you provide more details about what you are doing, someone can offer a more specific solution. 如果您提供有关您正在做的事情的更多详细信息,那么有人可以提供更具体的解决方案。

Maddy is right. 玛蒂是对的。 You need to reuse your cells, and i think it's the solution to solve your problem : 您需要重用您的单元格,我认为这是解决您的问题的解决方案:

  1. in your TableViewDelegate, call a method to update your cell content 在TableViewDelegate中,调用一种方法来更新单元格内容
  2. in this method, check if the texfield "isFirstResponder" 在此方法中,检查texfield是否为“ isFirstResponder”
  3. if it's true, call "resignFirstResponder" in your textfield 如果是真的,请在您的文本字段中调用“ resignFirstResponder”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM