у меня есть приложение, которое нужно, чтобы сделать свиток в целях сбора автоматически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()
}
}
}
что-х присоединять 3 клетки каждые три секунды
я просто нужно сделать прокручивать следующая строка, когда я добавить три клетки
self.collectionView.layoutIfNeeded()
self.collectionView.scrollToItemAtIndexPath(NSIndexPath(index: self.scrollIndex), atScrollPosition: UICollectionViewScrollPosition.Bottom, animated: true)
но краш-приложение и ошибка:
Нагрузочного приложение из-за неперехваченное исключение «NSInvalidArgumentException», причина: «попытка перехода к недопустимому пути индекса: {длина = 1, путь = 6}»
кто может помочь
doAfterThreeSecods называет это сам после каждого 3sec. и как collectionView.reloadData() вызывается здесь, так что это также вызов после каждых 3 секунд. – Sofeda
scrollIndex не увеличивается в doAfterThreeSecond вызывает –
прокрутка перед добавлением ячейки или неправильным номером ячейки, ее 0-> 5 для 6 ячеек – Tj3n