具有UITextField的UITableView-即使在用户滚动后仍保留数据 [英] UITableView with UITextField - keep the data even after user scrolls

查看:62
本文介绍了具有UITextField的UITableView-即使在用户滚动后仍保留数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,并且有一堆UITableViewCells-这些UITableViewCells里面有多个UITextField。

I have a UITableView and it has bunch of UITableViewCells - These UITableViewCells have multiple UITextFields inside it.

现在每次我上下滚动时-UITableViewCells都会不在视野范围之内-并返回到我在UITextField中输入的所有文本都消失了-使其最佳工作方式是什么?

Now every time I scroll up and down - and the UITableViewCells go out of the view - and comes back in whatever text I enter inside the UITextField disappears - What is the best way to make this work?

推荐答案

创建一个 NSMutableArray ,该位置在每个位置都保存一个与每个单元格匹配的 NSString 对象。

create an NSMutableArray which at each position, holds an NSString object which matches each cell.

当您配置+显示中的每个单元格时-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ,将 UITextField 的文本设置为数组中位于位置 indexPath.row 的字符串。

when you config + show each cell in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath, set the text of the UITextField to the string in the array at position indexPath.row.

编辑 UITextField 时,在 NSString 对象上插入/更新。数组中当前 indexPath.row 位置

when editing a UITextField, insert/update the NSString object at the current indexPath.row position in the array

这篇关于具有UITextField的UITableView-即使在用户滚动后仍保留数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆