【问题标题】:iCarousel get user tapped indexiCarousel 获取用户点击的索引
【发布时间】:2016-07-12 11:38:22
【问题描述】:

我想获取用户点击的索引。我尝试了几种方法来检测它,但都没有奏效。 这是我尝试过的。

   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 :)")

【问题讨论】:

  • 假设在didSelectItemAtIndex方法中检测到点击。你设置好委托了吗?
  • @cod3rite,在我设置委托后,轮播显示第一条或最后一条记录。
  • 检测到点击了吗?
  • 不,但 carouselCurrentItemIndexDidChange 正在被调用
  • didSelectItemAtIndex 也被调用?

标签: ios swift icarousel


【解决方案1】:

可能没有帮助,因为我使用的是 Objective-C,但在

中检测到了水龙头
- (void)didTap:(UITapGestureRecognizer *)tapGesture 

方法。

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

按预期工作。我正在使用 iCarousel 版本 1.8.2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 2017-02-23
    • 1970-01-01
    • 2012-02-06
    相关资源
    最近更新 更多