问题标签 [prepareforreuse]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
3066 浏览

ios - 如何在旋转后重绘不可见的 UICollectionViewCell 以备重用?

如何在重用发生时重绘不可见的 UICollectionViewCell 准备好???

我想到的一种方法是根据布局单元 prepareForReuse 函数中的代码,但是虽然它的工作方式不是最佳的,因为它会导致更多的重新绘制然后需要。

背景:需要在drawRect当前不可见的方向更改后触发单元格,但弹出以供使用且尚未重绘,到目前为止我只能看到这prepareForReuse是合适的。问题是我正在重新绘制所有“重用”单元格,而我真的只想重新绘制最初弹出的那些在设备的先前方向位置期间创建的那些。

附加信息:所以目前我正在这样做:

在视图控制器中:

在布局单元类中:

没有上面 prepareForReuse 中的代码会发生什么的示例。在方向更改后拍摄的快照,并且在向上滚动一点后拍摄:

在此处输入图像描述

0 投票
1 回答
1293 浏览

swift - Values Repeat When Scrolling in TableView

When I tap a button in a custom cell and then scroll down (or up) another cell button is also tapped. I see that it's tapped because the button outlet that I created for the button is disabled.

My cellForRowAtIndexPath has a reuseIdentifier for the cell:

Considering I have the degueueReusableCellWithId in the cellForRowAtIndexPath do I need a prepareForReuse? When I add the prepareForReuse in my custom cell file, the cell just goes back to the default values (obviously because I reset it to the default values). Problem is I want it to keep the value of each indexPath.row.

This is how I'm querying the values:

This is the numberOfRowsInSection and cellForRowAtIndexPath

I'm registering this in the viewDidLoad above the super.viewDidLoad()

This is my button query in the customCell:

Any help and suggestions mean a lot.

Thank you.


REFRENCE LINKS I USED:

I referred to several links but they were in objective-c and didn't help:

UICollectionView Tap Selects More Than One Cell

How to use prepareForReuse method

I also referred to the docs, and that didn't help much.

0 投票
2 回答
4573 浏览

ios - CollectionViewCell 中的 PrepareForReuse

我想将标签隐藏在被点击的单元格中,而是显示图像。但我只想在具有特定索引的单元格已设置为 imageView 时才这样做。如果将单元格设置为 imageView,则处理单元格和存储的最佳方法是什么?我该如何使用该prepareForReuse方法?

直到现在我都是这样做的,但是因为细胞被重复使用了。图像在滚动时显示在其他单元格中。

0 投票
2 回答
1442 浏览

ios - 如何在 Objective-c 的 UICollectionView 中保留 didSelect 操作?

我有一个 UICollectionView 并从我的 cellForItemAtIndexPath 12 个单元格中添加。当我滚动查看向下单元格时,所有功能都被保留,但是当我再次滚动向上时,某些单元格不会执行在 didSelectItemAtIndexPath 中加载的函数。

我设置禁用了一些行。但不是我单击的行为什么会这样?重用电池可能是一个糟糕的准备吗?

我正在尝试重用功能,但这只会影响将单元格绘制错误或在另一个位置上,并且在 didSelectItemAtIndexPath 中添加的功能不起作用:

当我滚动并单击一个单元格时,这不会打开我的 secondViewController,我认为该单元格的索引错误已被禁用。

在我的单元格中,我添加了 prepareForReuse 但这不起作用......

0 投票
2 回答
27485 浏览

ios - 使用 prepareForReuse 的正确方法是什么?

需要帮助了解如何在 UIKit 中使用 prepareForReuse()。文件说_

您应该只重置与内容无关的单元格属性,例如 alpha、编辑和选择状态

但是如何重置单个属性属性,例如 isHidden?

假设我的单元格有 2 个标签,我应该在哪里重置:

  1. 标签.文本
  2. label.numberOfLines
  3. label.isHidden

我的 tableView(_:cellForRowAt:) 委托具有条件逻辑来隐藏/显示每个单元格的标签。

0 投票
1 回答
2051 浏览

swift - 为什么应用程序会因 [NSObject(NSObject) doesNotRecognizeSelector:] 而崩溃?

该应用程序有时会崩溃[NSObject(NSObject) doesNotRecognizeSelector:],选择器为[UIImageView setImage:].

在此处输入图像描述

我通过设置异常断点来捕获它,并且在设置 a 时UIImageView.image发生prepareForReuse崩溃UICollectionViewCell

prepareForReuse调用然后单元被实例化:

为什么会这样?

此外,我无法加载快速查看数据视图,UIImageView所以该对象可能已被释放?

在此处输入图像描述

控制台中的错误消息是:

0 投票
1 回答
353 浏览

ios - TableViewCell doesn't reload as expected

I have a little app that tracks players playing time in a sports game. I have a list of sports games, and you can click into one and start tracking game details. I'm trying to make it so that if a game is in progress and a user goes back to the list of games, that they can't click on another game cell as it overwrites all the current data in the active game.

I've almost made this work. When a game is in progress and I go back to the list of sports games, only the active one is accessible and shows to the user that it's active. But when I go back and reset that game, I expect the tableView of sports games to all be accessible. But they are not. It still shows only one active game and all the other games are inaccessible. I am using tableView.reloadData within viewWillAppear. I've shown the relevant code below also.

Now this works when I have a game in progress. I go back to the game list and the active game is accessible and shows the little label and all the other games cells are inactive. But if I go back and reset the game, so it's no longer active, all the games should be displayed and be accessible. But the game that was active is still shown as active and all the other game cells are inaccessible.

I've confirmed that when I've reset the game that it isn't being classed as still active by printing out a message in the isAnyGamesInProgress() call in configureFixtureCell(). So unsure why the rows don't seem to update, especially as I'm reloading the table when the game list controller willAppear()?? and I'm not caching the result of the games NSFecthController :)

I've attached some images to show the console output too. First is the initial load

Initial Load

Game in progress enter image description here

After game resetenter image description here

0 投票
1 回答
412 浏览

ios - prepareForReuse 无法与 imageView 一起正常工作

每当我的 isLive 函数返回 true 时,我都会尝试向图像视图添加底部边框。我检查了该部分,它只执行一次。但是,有多个带有蓝色底边框的单元格。此代码如下所示:

我的 addBottomBorderWithColor 是一个扩展,看起来像这样:

据我所知,我需要删除 prepareForReuse 函数中的底部边框。我尝试使用其他扩展名将其删除:

prepareForReuse 是正确的方法还是我需要以其他方式设置它?

我通过以下方式调用 prepareForReuse :

0 投票
1 回答
164 浏览

ios - 当第二个视图控制器发送数据时,Prepare For Segue 是否工作

几天前,当我学习如何将数据从一个 VC 发送到另一个 VC 时,我是 ios 开发的新手,然后我使用了

现在当从 secondVC 接收数据时,我也使用了与我在网上看到的几乎相同的代码

所以请任何人都可以快速解释为什么它看起来一样或有什么不同

0 投票
0 回答
465 浏览

ios - 一次选择 tableView 中的多个部分

我有一个扩展的 TableView,其中 HeaderView 包含一个复选框、一个标签和一个单选按钮。

复选框可以有多个选择。但是radioButton 只有单选。如果选择了另一个单选按钮,则在 tableView 中取消选择先前选择的按钮

我的问题是,每当我在第 0 节选择一个单选按钮时,第 8 节和第 16 节的单选按钮也会被选中。滚动单选按钮后,它的状态会发生变化。任何部分的任何单选按钮都会被选中。我知道这是由于 tableView 的单元格重用属性,但我不知道如何解决这个问题。我在这里提到了很多关于 SO 的解决方案,但似乎没有一个有效。这个问题对我来说真的很麻烦,因此我无法进一步进行。如果有错误或我遗漏了什么,请指导我。非常感谢帮助。谢谢!

这是我的tableView HeaderView 的代码:

这是我的 ViewController 类:

预期输出:

在此处输入图像描述

我得到了什么:

在此处输入图像描述