Uitableview 另一个表视图内的表视图,内部表视图具有动态高度
我是iOS开发新手。我试图实现的目标是在另一个tableView中有一个tableView,并且必须对该tableView中的项目进行选择。当我实现这一点时,面临着一些问题Uitableview 另一个表视图内的表视图,内部表视图具有动态高度,uitableview,swift3,Uitableview,Swift3,我是iOS开发新手。我试图实现的目标是在另一个tableView中有一个tableView,并且必须对该tableView中的项目进行选择。当我实现这一点时,面临着一些问题 我需要有一个动态的表格视图高度(即,第一次加载时,内部表格视图的高度只能显示3个单元格,单击外部表格视图单元格中的“显示更多”按钮时,外部表格视图单元格将展开并显示内部表格视图中的剩余单元格) 在内部表格视图中选择一个单元格时,内部表格视图中的同一单元格以及所有其他单元格也会被选中 我附加的代码,我做了什么,我试图实现的
- 我需要有一个动态的表格视图高度(即,第一次加载时,内部表格视图的高度只能显示3个单元格,单击外部表格视图单元格中的“显示更多”按钮时,外部表格视图单元格将展开并显示内部表格视图中的剩余单元格)
- 在内部表格视图中选择一个单元格时,内部表格视图中的同一单元格以及所有其他单元格也会被选中
extension Explore:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 13
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = exploreTableView.dequeueReusableCell(withIdentifier: "exploreCell", for: indexPath) as! ExploreAlbumPosting
if isExpanded{
cell.showMoreBtn.setTitle("Show Less", for: .normal)
cell.showMoreBtn.setImage(#imageLiteral(resourceName: "ic_arrow_drop_up"), for: .normal)
}
else{
cell.showMoreBtn.setTitle("Show More", for: .normal)
cell.showMoreBtn.setImage(#imageLiteral(resourceName: "ic_arrow_drop_down"), for: .normal)
}
cell.showMoreBtn.addTarget(self, action: #selector(showMoreBtnTapped(sender:)), for: .touchUpInside)
cell.showMoreBtn.tag = indexPath.row
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if isExpanded && selectedIndex == indexPath{
return 180 * numberOfRowsInInnerTableView
}
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 215
}
}
显示更多Btn Tapp动作
func ShowMoreBntap(发送方:UIButton){
}
内部表视图方法(扩展到外部表视图的customcell类-UITableViewCell)
请帮帮我,谢谢
let row = sender.tag
self.selectedIndex = IndexPath(item: row, section: 0)
isExpanded = !isExpanded
self.exploreTableView.reloadRows(at: [selectedIndex!], with: .automatic)
self.exploreTableView.scrollToRow(at: selectedIndex!, at:UITableViewScrollPosition.middle, animated: true)
extension ExploreAlbumPosting:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = innerAlbumTableView.dequeueReusableCell(withIdentifier: "ExploreAlbumInnerCell", for: indexPath)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 92
}
}