0
BigBasket.com과 같은 가로 슬라이더를 만들려고합니다. 나는 페이징을 위해 collectionview를 사용하고있다. 나는 항목을 가로, 자동 및 수동으로 스크롤하는 데 성공합니다. 하지만 3 초마다 다음 셀을 하나씩 강조하는 방법을 알지 못합니다. 제게이 일을하도록 도와주세요.CollectionView는 3 초마다 자동으로 다음 셀로 강조 표시됩니다.
override func viewDidAppear(animated: Bool) {
rowToHighlight = 0;
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: #selector(BannerTagCollectionViewController.ScrollToNextCell), userInfo: nil, repeats: true)
}
func ScrollToNextCell() {
rowToHighlight += 1
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: #selector(BannerTagCollectionViewController.ScrollToNextCell), userInfo: nil, repeats: true)
}
// MARK: UICollectionViewDataSource
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return bannerTagArray.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : BannerTagCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! BannerTagCollectionViewCell
if(indexPath.row == self.rowToHighlight){
cell.backgroundColor = UIColor .whiteColor()
cell.selectedView.backgroundColor = UIColor .greenColor()
}
else{
cell.backgroundColor = UIColor .lightGrayColor().colorWithAlphaComponent(0.5)
cell.selectedView.backgroundColor = UIColor .clearColor()
}
// Configure the cell
cell.bannerTagProNameLbl?.text = bannerTagArray[indexPath.row]
cell.bannerTagProDescLbl?.text="bbbbnn"
return cell
}
신속하게 코드를 변환하여 시도했습니다. 하지만 작동하지 않습니다. 첫 번째 셀만 강조 표시됩니다. 코드를 업로드했습니다. – user3516627
@ user3516627, * ScrollToNextCell * 메소드에 * self.collectionView! .reloadData() *를 추가하는 것을 잊어 버렸습니다. 그렇기 때문에 반복 매개 변수가 필요하지 않습니다. – PrafulD
예. 그것은 작동합니다. 감사. – user3516627