0

My iCarousel inside a TableView won't move when I modify CGRect position. Here's how the simulator look like: iCarousel centered vertically and all the way to the top

I included the whole code block. I'm a noob and this is my first app. Apologies.

UIViewController code:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


var gameTitles = ["Game Title 1", "Game Title 2", "Game Title 3", "Game Title 4", "Game Title 5" ]
// Place Holders for game titles

func numberOfSections(in tableView: UITableView) -> Int {
    return gameTitles.count
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    let screenHeight = UIScreen.main.fixedCoordinateSpace.bounds.height - 113
    tableView.rowHeight = screenHeight
    return gameTitles[section]
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CarouselView
    return cell
}

UITableViewCell code:

import UIKit

class CarouselView : UITableViewCell, iCarouselDelegate, iCarouselDataSource {

@IBOutlet var carouselView: iCarousel!
var gameImages = [1,2,3,4,5,6,7,8,9,10]

override func awakeFromNib() {
    carouselView.type = .coverFlow2

}

func numberOfItems(in carousel: iCarousel) -> Int {
    return gameImages.count
}

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
    let cellWidth = UIScreen.main.bounds.size.width - 40
    let logView = UIView(frame: CGRect(x: 0, y: 0, width: cellWidth, height: cellWidth))
    logView.backgroundColor = UIColor.red
    logView.layer.borderColor = UIColor.black.cgColor
    logView.layer.borderWidth = 3.0
    return logView
}

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    if option == iCarouselOption.spacing{
        return value * 1.1
    } 
    return value
Theomars
  • 1
  • 1

1 Answers1

0

From README on GitHub:

- (void)reloadData;

This reloads all carousel views from the dataSource and refreshes the carousel display.

I suppose you should reload @IBOutlet var carouselView: iCarousel! at some point to let carouselView rearrange itself.

Community
  • 1
  • 1
Yakiv Kovalskyi
  • 1,737
  • 1
  • 15
  • 29