ios - 如何在不重新加载Objective-C中的行的情况下更改行中的特定元素?
问题描述
我想UiSwitch
在UITableView
. 我想以编程方式打开和关闭动画。
NSIndexPath *indexPath = [[NSIndexPath indexPathForRow:0 inSection:lastSelectedCardSectionNumber] retain];
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
[cell.switch1 setOn:YES animated:YES];
但是上面的行不会改变状态,我必须重新加载不会使 UiSwitch 状态随动画变化的行。
开关顶部有一个视图,用户可以点击它来更改开关的状态。但它应该在某些情况下改变。因此我不允许用户更改它我想以编程方式更改它。
解决方案
问题在于您如何检索cell
. 它应该是:
newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];
不是这个:
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
前者获取已存在的单元格实例,但后者创建单元格的新实例。
推荐阅读
- machine-learning - 哪里可以便宜地托管小型 GPU 机器学习 API
- c++ - 从列表 C++ 中删除相关对象
- javascript - 从自定义 Google 表格函数返回二维数组时,从类中检索的值留空
- arrays - 返回数组的两个指针
- javascript - 如何获取具有最接近数字的数组中的对象元素?
- sql - 从父行中选择属性(并包括子行的成本)
- typescript - 具有混合对象的打字稿数组
- ruby-on-rails - 如何在 Rails 6 和 Webpacker(以及 bootstrap 和 SASS/SCSS)中安装自定义字体
- python - 如何在没有 root 权限的情况下在 conda 中安装 pip 包?
- php - 如何在 Laravel 8 中全局使用表单中的变量?