我是swift和iOS开发的新手。我想在swift中创建包含集合视图的tableview。我能够做到目前为止,但我的问题出现时收集视图中的项目数量和没有。 tableview中的行取决于我检索的json数据。我无法在集合视图中编辑项目数量。我为tableviewcell和collectionviewcell使用自定义单元类。如何更改数据在表中的的CollectionView小区中的每个表行differently.code收集视图代表如何在动态的uitableview中创建动态的uicollectionview
func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return array_servicelist.objectAtIndex(something).valueForKey("subCategoryList")!.count
}
func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectioncell",
forIndexPath: indexPath) as! ServiceCollectionViewCell
let str :String = "\(array_servicelist.objectAtIndex(indexPath.section).valueForKey("subCategoryList")!.objectAtIndex(indexPath.item).valueForKey("phoneImageUrl") as! String)"
cell.serviceImage.image = UIImage(data: NSData(contentsOfURL: NSURL(string: str)!)!)
cell.serviceName.text = "\(array_servicelist.objectAtIndex(indexPath.section).valueForKey("subCategoryList")!.objectAtIndex(indexPath.item).valueForKey("categoryName") as! String)"
return cell
}
为代表的tableview代码
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return array_servicelist.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("tablecell", forIndexPath: indexPath)
return cell
}
func tableView(tableView: UITableView,
willDisplayCell cell: UITableViewCell,
forRowAtIndexPath indexPath: NSIndexPath) {
guard let tableViewCell = cell as? ServiceTableViewCell else { return }
tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
集合视图在表格行内吗? –
是集合视图是表行,包含图像和标签 –
cellforrowatndexpath是只返回细胞没有别的 FUNC的tableView中(的tableView:UITableView的,的cellForRowAtIndexPath indexPath:NSIndexPath) - > {UITableViewCell中让 细胞= self.tableView.dequeueReusableCellWithIdentifier (“tablecell”,forIndexPath:indexPath) return cell } –