ios - xib创建的cell重用问题
迷茫
迷茫 2017-04-17 17:47:27
0
2
192

xib创建的cell中添加一个UITextField,如果重用会导致后来在UITextField手动输入的数据混乱,如果不重用会导致内存问题,求解决方案!

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
PHPzhong

重用的时候清理一下历史数据呗, UITableViewCell 有个 prepareForReuse 方法,每次在将要重用前都会调用,你可以在这里清理之前的旧数据。

public func prepareForReuse() // if the cell is reusable (has a reuse identifier), this is called just before the cell is returned from the table view method dequeueReusableCellWithIdentifier:.  If you override, you MUST call super.
大家讲道理

在cellForRowAtIndexPath方法中return cell之前, 对cell再赋值一次,比如:写一个类textField, cell.testField = self.data[indexPath.row]; 这里的data数组放的是你自定义的类textField,或者直接给cell搞个属性 fieldText, 返回之前再赋值一遍 cell.fieldText = @"测试";

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!