0
我想獲取用戶點擊的索引。我嘗試了幾種方法來檢測它,但它們都沒有工作。 這是我試過的。iCarousel獲取用戶點擊索引
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'法檢測水龍頭。你是否設置了委託? – xmhafiz
@ cod3rite,在設置委託後,Carousel顯示第一個或最後一個記錄。 – onkar
是檢測到的龍頭? – xmhafiz