相关疑难解决方法(0)

为什么UICollectionView的UICollectionViewCell没有突出显示用户触摸?

我有一个UICollectionView,它由一个自定义的UICollectionViewCell子类组成.单元格正确显示,并通过触发此方法正确响应用户的触摸:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

但是,我理解当用户触摸单元格时,它应该突出显示(蓝色),然后当用户抬起手指时高光应该消失.这不会发生.有什么想法吗?

这是一些相关的代码:

在UICollectionView的数据源中:

@implementation SplitCheckViewCollection

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"ReceiptCellIdentifier";
    SplitCheckCollectionCell *cell = (SplitCheckCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.cellName.text = [NSString stringWithFormat:@"%@%i",@"#",indexPath.row+1];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

在UICollectionViewCell的实现中:

@implementation SplitCheckCollectionCell

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SplitCheckCollectionCell" owner:self options:nil];

        if ([arrayOfViews count] < 1) {
            return nil;
        }

        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
            return nil;
        }

        self = [arrayOfViews objectAtIndex:0];    
    } …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview

39
推荐指数
6
解决办法
5万
查看次数

更改UICollectionView单元格的背景

我有一个以编程方式创建的UICollectionView.我希望集合视图以下列方式运行:

1. User touches cell
2. Cell background color changes
3. User releases touch
4. Cell background color changes
Run Code Online (Sandbox Code Playgroud)

这应该是一个快速的颜色更改,它发生在与执行tap操作相关的选择器之前,其中包含集合视图的viewcontroller从堆栈中弹出.

我一直在看这个问题:UICollectionView单元格改变背景,同时点击

其中有以下用于此目的的方法摘要:

// Methods for notification of selection/deselection and highlight/unhighlight events.
// The sequence of calls leading to selection from a user touch is:
//
// (when the touch begins)
// 1. -collectionView:shouldHighlightItemAtIndexPath:
// 2. -collectionView:didHighlightItemAtIndexPath:
//
// (when the touch lifts)
// 3. -collectionView:shouldSelectItemAtIndexPath: or -    collectionView:shouldDeselectItemAtIndexPath:
// 4. -collectionView:didSelectItemAtIndexPath: or -collectionView:didDeselectItemAtIndexPath:
// 5. -collectionView:didUnhighlightItemAtIndexPath:
Run Code Online (Sandbox Code Playgroud)

我假设我只需要从"触摸开始时"和"触摸结束时"实现上述方法之一.但无论我做什么,似乎背景颜色会发生变化,然后仍然会发生变化.这是我尝试过的一些不起作用的例子:

- (void)collectionView:(UICollectionView …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell uicollectionviewdelegate

32
推荐指数
3
解决办法
4万
查看次数