iosswifticarousel

iCarousel get user tapped index


I want to get the index that user has tapped.I have tried several ways to detect it but none of it is working. Here is what I have tried.

   func carousel(carousel: iCarousel, didSelectItemAtIndex index: Int) {
        print("this has been tapped from Carousel \(index)")
    }

    func carouselCurrentItemIndexDidChange(carousel: iCarousel) {
        let index=carousel.currentItemIndex
        print("this is current index \(index) ")
    }

    func carousel(carousel: iCarousel, viewForItemAtIndex index: Int, reusingView view: UIView?) -> UIView {
        let webV:WKWebView!
        webV = WKWebView(frame: CGRectMake(10, 10, 250, 250))
        if let updatedResource = myDict[index+1]{//name of resource I want to load
            let url =  NSBundle.mainBundle().URLForResource(updatedResource, withExtension: "html")
            let requestObj = NSURLRequest(URL: url!);
            webV.loadRequest(requestObj);
            let tapGesture = UITapGestureRecognizer(target: self , action: Selector("tapDetected"))
            //tapGesture.numberOfTapsRequired = 2
            tapGesture.enabled = true
            webV.userInteractionEnabled = true
            webV.addGestureRecognizer(tapGesture)

           // setUserInteractionEnabled = true
            print("this has been rendered \(index)")
          }
        return webV

    }

    func tapDetected(sender:UISwipeGestureRecognizer) {
        print("yes tap has been detected :)")

Solution

  • Might not help since I'm using the Objective-C but the tap is getting detected in the

    - (void)didTap:(UITapGestureRecognizer *)tapGesture 
    

    method.

     [_delegate carousel:self didSelectItemAtIndex:index];
     NSLog(@"Selected app at index: %d", index);
    

    works as expected. I'm using iCarousel version 1.8.2