Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios tableviewcell中uicollectionviewcells中的选择数存在问题_Ios_Swift - Fatal编程技术网

Ios tableviewcell中uicollectionviewcells中的选择数存在问题

Ios tableviewcell中uicollectionviewcells中的选择数存在问题,ios,swift,Ios,Swift,当我想在UITableViewCell中返回一定数量的UICollectionViewCell时,它的行为非常奇怪,我就是想不出问题所在,在前三个单元格开始变得一团糟之后,它开始返回与前两个相同的值,以便更好地解释: 变量计数:[Int]=[2,3,4,5,6] -第一个UITableViewCell根据计数数组为我提供2个uicollectionviews。 -第二个UITableViewCell根据计数数组提供3个uicollectionviews。 -第三个UITableViewCell根

当我想在UITableViewCell中返回一定数量的UICollectionViewCell时,它的行为非常奇怪,我就是想不出问题所在,在前三个单元格开始变得一团糟之后,它开始返回与前两个相同的值,以便更好地解释:

变量计数:[Int]=[2,3,4,5,6] -第一个UITableViewCell根据计数数组为我提供2个uicollectionviews。 -第二个UITableViewCell根据计数数组提供3个uicollectionviews。 -第三个UITableViewCell根据计数数组为我提供了4个uicollectionviews。 -第四个UITableViewCell给我2个uicollectionviews,根据我的计数数组,它应该是5,但它决定不这样做。 -第五个UITableViewCell给我3个uicollectionviews,根据我的计数数组,它应该是6,但它决定不这样做

  • 我已经尝试过使计数数组基于我自己单独的int值,并且它仍然做相同的事情
  • 我尝试过使用编程的uicollectionview,而不是使用故事板,它只是做了同样的事情
变量计数:[Int]=[2,3,4,5,6]

类项目:UITableViewController{

override func viewDidLoad() {
    super.viewDidLoad()
    SetUp()
}

func SetUp() {
    self.definesPresentationContext = true
}
}

扩建项目{

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let Cell: TableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
    print(indexPath.row)
    Cell.CollectionCount = Count[indexPath.row]
    Cell.ProjectText = "Hello"
    return Cell
}
}

类TableViewCell:UITableViewCell、UICollectionViewDelegate、UICollectionViewDataSource{

@IBOutlet weak var ProjectLabel: UILabel!
@IBOutlet weak var CollectionView: UICollectionView!

var ProjectText: String?
var CollectionCount: Int?

override func layoutSubviews() {
    super.layoutSubviews()
    ProjectLabel.text = ProjectText!
    CollectionView.delegate = self
    CollectionView.dataSource = self
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return CollectionCount!
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let Cell: UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
    return Cell
}
}

  • 第一个UITableViewCell应该为我提供2个uicollectionviews
  • 第二个UITableViewCell应该为我提供3个uicollectionviews
  • 第三个UITableViewCell应该为我提供4个uicollectionviews
  • 第四个UITableViewCell应为我提供5个uicollectionviews
  • 第五个UITableViewCell应该为我提供6个uicollectionviews

电池可重复使用。更改
count
属性时,需要重新加载集合视图;使用
didSet
观察者。此外,按照惯例,Swift变量和属性以小写字母开头。类、结构和协议以大写字母开头。采用此约定将使您的代码对其他人更清晰。单元格将被重用。更改
count
属性时,需要重新加载集合视图;使用
didSet
观察者。此外,按照惯例,Swift变量和属性以小写字母开头。类、结构和协议以大写字母开头。采用此约定将使您的代码对其他人更清晰。