如何获得按钮上的indexPath of collectionViewCell,单击按钮,按钮从collectionviewCell中脱离出来。我正在和sender和Superview合作。但这是行不通的。
@IBAction func btnCancel(_ sender: Any) {
if let cell = (sender as AnyObject).superview??.superview?.superview?.superview?.superview?.superview as? ImageShowinPopUpCell {
let indexPath
我使用的是CollectionView和UIButton。我的代码也面临着一些问题。我想在单击按钮时访问collectionViewCell。按钮在collectionView的外面。那么,我该如何访问它呢?
if let cell = (sender as? UIButton)?.superview?.superview?.superview as? FavouriteVideosCell
{
let index = collectionview.indexPath(for: cell)
let video_id = arrayFavouriteVid
我想做这样的东西。
(1)。如果我按下31个按钮(A)中一个。该数字(A)变为红色。
(2)。然后,如果我按下另一个按钮(B),那么(A)再次变为黑色,然后(B)变为红色。
**
class ViewController: UICollectionViewController {
var collectionViewCell = CollectionViewCell()
let data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
override func
当长时间按下UICollectionView中的单元格时,我想显示一个删除按钮。当我单击该单元格时,它将显示,而当单击该单元格外部时,它得到异常,"fatal error: unexpectedly found nil while unwrapping an Optional value"如何解决?我的代码如下所示
func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {
if gestureReconizer.state == UIGestureRecognizerState.Be
我正在用一个充满自定义CollectionViewCell的CollectionViewCell构建一个应用程序。
我添加了一个按钮"select all /取消select all“,这显然会影响到我的collectionView中的所有单元格。为了做到这一点,我打算使用如下的for-循环:
for(customCollectionViewCell* cell in self.collectionView){
// some code
}
然而,我第一次收到警告时说:
Collection expression type "UICollectionView *
我有一个非常简单的CollectionView,它显示4个按钮,每个按钮都有海龟的名字。当我单击任何按钮时,我希望刷新我的CollectionView,以防我的数组增加并添加了第5个名称,该名称应显示为第5个按钮。这基本上是有效的,但当我按下并释放任何按钮时,按钮标题会显示我的数组,从最后到第一个,然后切换回第一个到最后一个。 有人知道它为什么这么做吗?我怎么才能阻止它呢? 我只想在每次按下按钮时更新我的CollectionView。如果数组应该增加,假设是"Splinter",我希望Button标题在前四个按钮上保持不变,只添加第五个按钮。 非常感谢您的提前! class