【问题标题】:Switched from tableview to colelctionview now didselectitematindexpath not called从 tableview 切换到 colelctionview 现在没有调用 didselectitematindexpath
【发布时间】:2015-04-20 07:42:16
【问题描述】:

所以我从 UITableView 切换到 UICollectionView。单元格都加载得很好,看起来很漂亮,但现在我不能再选择它们中的任何一个了。水龙头在日志中被识别,但它并没有把我带到它应该带我去的视图。

真正改变的唯一内容是您在“cellForItem”部分中看到的那些被注释掉的内容。其他一切都与它在 TableView 中工作时的情况相同。它只是应该将我带到您点击时指定的 ViewController。相反,轻拍被记录下来,但它什么也没做。任何帮助将不胜感激。

我也尝试摆脱 [collectionView deselectItemAtIndexPath:indexPath animated:YES];

...但没有任何区别。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        PlaceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    // Configure the cell
    //UINib * placeCell = [UINib nibWithNibName:@"Shops" bundle:nil];
   // NSArray *topLevelItems = [placeCell instantiateWithOwner:self options:nil];      

   // cell = [topLevelItems objectAtIndex:0];

    Place *p = [_entries objectAtIndex:indexPath.row];
    cell.placeName.text = p.PName;
    NSLog(@"p:%@",p.PName);
    cell.placeName.textColor = [UIColor colorWithRed:3/255.0f green:6/255.0f blue:4/255.0f alpha:1.0f];
    NSString *pIcon;
    pIcon = typeName;
    //NSLog(pIcon);
    cell.placeImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:p.PImage]]];
    NSLog(@"i:%@",p.PImage);
    return cell;
}

-(void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"Tap Recognized");
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    Place *p = [_entries objectAtIndex:indexPath.row];
    DetailPlaceViewController * pvc = [[DetailPlaceViewController alloc] init];
    [pvc setPlace:p];
    [self.navigationController pushViewController:pvc animated:YES];


}

【问题讨论】:

    标签: xcode uicollectionview didselectrowatindexpath


    【解决方案1】:

    这个很好玩……

    由于某些奇怪的原因,我的导航控制器无法正常工作......所以当然使用导航控制器加载视图是行不通的。足够简单的解决方案......在没有导航控制器的情况下加载视图。我只是想删除这个问题,但也许有一天有人会遇到类似的情况:

    [self presentViewController:pvc animated:YES completion:nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多