小编Cés*_*ins的帖子

在UICollectionView中处理Tap Gesture

因为我无法使用任何框架来创建相册,所以我正在尝试使用Collection View创建自己的框架,但是我在开始时就卡住了.

我的目标是将我的Web服务中的所有图像显示到我的集合视图中,因为所有图像显示,下一步是当有人点击任何单元格时,我可以在新视图中打开它并在所有图像之间导航.

这是我创建的基本代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [collectionController reloadData];
    tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:nil action:@selector(touched)];

    tapGesture.numberOfTapsRequired = 1;


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 6;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellIdentifier = @"Cell";

    CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    [cell.imgCollection setImageWithURL:[NSURL URLWithString:@"http://sallescds.com.br/wp-content/uploads/2012/12/xepop-300x300.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    [cell.imgCollection addGestureRecognizer:tapGesture];

    return …
Run Code Online (Sandbox Code Playgroud)

objective-c uitapgesturerecognizer uicollectionview

5
推荐指数
1
解决办法
3万
查看次数