をスクロール、私はのは私だけスクロールさせる必要がある3つのセルごとに3秒UICollectionView垂直に自動的に3秒ごとに
を追加し、自動的にコレクションビューのスクロールを行う必要があるアプリ
class resultsViewController: UIViewController , UICollectionViewDataSource , UICollectionViewDelegate {
@IBOutlet weak var collectionView: UICollectionView!
var numberCount = 3
var scrollIndex = 1
override func viewDidLoad() {
super.viewDidLoad()
let flow = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
let width = UIScreen.mainScreen().bounds.size.width - 6
flow.itemSize = CGSizeMake(width/3, width/3)
flow.minimumInteritemSpacing = 3
flow.minimumLineSpacing = 3
flow.sectionInset = UIEdgeInsetsMake(0.0, 0.0,10,0);
// Do any additional setup after loading the view.
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
self.doAfterThreeSecods()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("imageSearch", forIndexPath: indexPath) as! imagesCollectionViewCell
return cell
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return numberCount
}
func doAfterThreeSecods()
{
numberCount += 3
collectionView.reloadData()
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
self.doAfterThreeSecods()
}
}
}
を持っています私は三つのセル
self.collectionView.layoutIfNeeded()
self.collectionView.scrollToItemAtIndexPath(NSIndexPath(index: self.scrollIndex), atScrollPosition: UICollectionViewScrollPosition.Bottom, animated: true)
が、アプリケーションのクラッシュやエラーを追加次の行があった:
01キャッチされない例外により「NSInvalidArgumentException」、理由にアプリを終了:「無効なインデックスパスにスクロールしようとする試み:{長さ= 1、パス= 6}」
誰もがあなたがこれをやっている
doAfterThreeSecodsそれはすべての3秒後に自己だ呼んでいます。 collectionView.reloadData()がここで呼び出されると、3秒ごとに呼び出されるようになります。 – Sofeda
doAfterThreeSecondでscrollIndexがインクリメントされていない場合は、セルが追加される前にスクロールして –
が呼び出されているか、またはセル番号が正しく計算されていません。 – Tj3n