Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改TableViewCell以立即生效_Ios_Iphone_Uitableview_Uibutton - Fatal编程技术网

Ios 更改TableViewCell以立即生效

Ios 更改TableViewCell以立即生效,ios,iphone,uitableview,uibutton,Ios,Iphone,Uitableview,Uibutton,我有一个带有自定义单元格的TableView。单元中的一个子视图是UIButton。当用户单击按钮时,我希望背景发生变化。我让所有这些都起作用了。但问题是,我无法看到变化,直到我将受影响的细胞从屏幕上滚动,然后将其返回到屏幕上。但我想立即看到变化,而不需要屏幕上的屏幕外的部分。我该怎么做 有关我的实现的更多信息: 在方法(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)ind

我有一个带有自定义单元格的TableView。单元中的一个子视图是UIButton。当用户单击按钮时,我希望背景发生变化。我让所有这些都起作用了。但问题是,我无法看到变化,直到我将受影响的细胞从屏幕上滚动,然后将其返回到屏幕上。但我想立即看到变化,而不需要屏幕上的屏幕外的部分。我该怎么做

有关我的实现的更多信息:

在方法
(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
中,我有一行

....
[cell.myBtn addTarget:self action:@selector(onMyBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
然后在
onMyBtnTapped
方法中,我会影响颜色变化

因此,也许我需要做的是从父视图控制器(?)中重新绘制一个特定的单元格

再多一点


我已经使用
[self.tableView cellforrowatinexpath:indexPath]获取了单元格。但现在我有了这个细胞,我不知道如何让它重新绘制自己。我一直在安卓上做这个。我不知道如何在iOS上执行此操作。

您可以在单击按钮时重新加载UITableViewCell:

[self.tableView reloadRowsAtIndexPaths:@[indexPathOfGivenCell] withRowAnimation:UITableViewRowAnimationNone];

您应该能够在方法中放置以下内容

[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

您可以要求在可见行重新绘制单元格:

NSArray *visibleIndexPaths       = [tableView indexPathsForVisibleRows];
[self.tableView reloadRowsAtIndexPaths:visibleIndexPaths withRowAnimation: UITableViewRowAnimationFade];

在mybtntapped:
上显示
的内容以及更改背景的位置。在给定场景中,不必知道开始更新和结束更新。谢谢,谢谢。但如果没有包装,它就无法工作。所以+1我在别的地方有个bug。我修复了bug,并添加了包装器。但是我回去检查了一下,没有包装纸也能用。