某些集合视图单元 didSelectItemAtIndexPath 不起作用
Posted
技术标签:
【中文标题】某些集合视图单元 didSelectItemAtIndexPath 不起作用【英文标题】:some of the collection view cell didSelectItemAtIndexPath not working 【发布时间】:2014-06-25 12:05:38 【问题描述】:我已经被这个震惊了一段时间。我的错误是时间表中的某些单元格 didSelectItemAtIndexPath 没有调用。我在该方法上保留了一个断点,当我单击某些单元格时,该方法没有被调用。可能是什么问题呢。请看下面的代码
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
return 25;
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *) collectionView
return 1;
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
NSLog(@"item clicked");
CGRect rect = [collectionData layoutAttributesForItemAtIndexPath:indexPath].frame;
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:@"note"];
pc = [[UIPopoverController alloc] initWithContentViewController:vc];
[pc presentPopoverFromRect:rect inView:collectionData
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
NSLog(@" The index path is %@", indexPath);
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
// we're going to use a custom UICollectionViewCell, which will hold an image and its label
Cell *myCell = [collectionData dequeueReusableCellWithReuseIdentifier:@"TableCell"
forIndexPath:indexPath];
if (indexPath.row < 20 || indexPath.row == 22 )
myCell.roomLabel.text = [NSString stringWithFormat:@"%ld,%ld", (long)indexPath.row, (long)indexPath.section];
NSLog(@"cell no %ld" ,(long)indexPath.row );
myCell.subjectLabel.text =@"English";
myCell.cellView.backgroundColor= [UIColor grayColor];
[myCell.redXbuttonOutlet addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
if(isLongPressed)
[myCell.redXbuttonOutlet setHidden:NO];
else
[myCell.redXbuttonOutlet setHidden:YES];
else
myCell.userInteractionEnabled = NO;
[myCell.redXbuttonOutlet setHidden:YES];
myCell.cellView.backgroundColor= [UIColor whiteColor];
myCell.subjectLabel.text =@"";
myCell.roomLabel.text = @"";
return myCell;
-(void)buttonPressed:(id)sender
NSLog(@"Button");
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Delete session" message:@"Do you want to delete this session" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
【问题讨论】:
【参考方案1】:老兄,您已禁用某些单元格的用户交互。 检查下面的代码在 cellForItemAtIndexPath 内
else
myCell.userInteractionEnabled = NO; // <-----Note this Line
[myCell.redXbuttonOutlet setHidden:YES];
myCell.cellView.backgroundColor= [UIColor whiteColor];
myCell.subjectLabel.text =@"";
myCell.roomLabel.text = @"";
【讨论】:
你是对的,但如果我删除这一行,即 myCell.userInteractionEnabled = NO;下面的白色单元格,即 (20,0) , (21,0), (23,0) 和 (24,0) 被启用.. 我只希望这些单元格不应该有用户交互...... 我为此添加了一些代码...我添加了 if (indexPath.row nandri bro... 很高兴看到一个拥有 14.5k 声望的塔米兰人 :-) 非常感谢您的问候,伙计,但我希望我们应该停止此聊天,因为在 Stack Over Flow 中,超出主题将被视为冒犯。以上是关于某些集合视图单元 didSelectItemAtIndexPath 不起作用的主要内容,如果未能解决你的问题,请参考以下文章
RxSwift MVVM 表视图/集合视图,用户输入单元表示状态