Ios UITableView留下了很大的空白
因此,我一直在与他的问题作斗争,如果UITableView不返回任何数据,就会留下很大的缺口。。如果它返回数据,就可以了 下面是显示错误的图像 我希望tableView在注释开始之前的单元格处完成 这是TableView数据源的代码Ios UITableView留下了很大的空白,ios,swift,uitableview,Ios,Swift,Uitableview,因此,我一直在与他的问题作斗争,如果UITableView不返回任何数据,就会留下很大的缺口。。如果它返回数据,就可以了 下面是显示错误的图像 我希望tableView在注释开始之前的单元格处完成 这是TableView数据源的代码 // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 9 + comments.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell1", forIndexPath: indexPath) as! vlcTableViewCell
// Configure the cell
cell.viewsCount.text = "\(shot.viewsCount)"
cell.likesCount.text = "\(shot.likesCount)"
cell.commentCount.text = "\(shot.commentCount)"
return cell
} else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as! descCell
// Configure the Cell
cell.usernameLabel.text = "\(shot.user.username)"
cell.descriptionLabel.text = "\(shot.description)"
cell.profileImageView.sd_setImageWithURL(NSURL(string: shot.user.avatarUrl), placeholderImage: UIImage(named: "2"))
return cell
} else if indexPath.row == 2 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell3", forIndexPath: indexPath)
return cell
} else if indexPath.row == 3 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell4", forIndexPath: indexPath) as! teamCell
if shot.team == nil{
cell.teamNameLabel.text = "Team"
} else {
cell.teamNameLabel.text = "\(shot.team.name)"
}
return cell
} else if indexPath.row == 4 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell5", forIndexPath: indexPath) as! reboundShotsCount
cell.reboundCountLabel.text = "\(shot.reboundCount)"
return cell
} else if indexPath.row == 5 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell6", forIndexPath: indexPath)
return cell
} else if indexPath.row == 6 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell7", forIndexPath: indexPath) as! attachmentShotsCount
cell.attachmentCountLabel.text = "\(shot.attachmentsCount)"
return cell
} else if indexPath.row == 7 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell8", forIndexPath: indexPath)
return cell
} else if indexPath.row == 8 {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell9", forIndexPath: indexPath)
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell10", forIndexPath: indexPath) as! CommentCell
//let comment = comments[indexPath.row]
//cell.nameLabel.text = comment.user.name
return cell
}
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
// #warning Incomplete implementation, return the height for each cell
if indexPath.row == 0 {
return 55.0
} else if indexPath.row == 1 {
return 55.0
} else if indexPath.row == 2 {
return 40.0
} else if indexPath.row == 3 {
if shot.team == nil {
return 0.0
}else {
return 40.0
}
} else if indexPath.row == 4 {
if shot.reboundCount == 0 {
return 0.0
} else {
return 37.0
}
} else if indexPath.row == 5 {
if shot.reboundCount == 0 {
return 0.0
} else {
return 90.0
}
} else if indexPath.row == 6 {
if shot.attachmentsCount == 0 {
return 0.0
} else {
return 37.0
}
} else if indexPath.row == 7 {
if shot.attachmentsCount == 0 {
return 0.0
} else {
return 90.0
}
} else if indexPath.row == 8 {
return 40.0
} else {
// This is the code for the comment cells
if shot.commentCount == 0 {
return 0.0
} else {
return 70.0
}
}
}
}
我的headerView的代码如下
var headerView : UIView!
let device = Device()
private var kTableHeaderHeight : CGFloat = 300.0
@IBOutlet weak var bgImageView: FLAnimatedImageView!
override func viewDidLoad() {
super.viewDidLoad()
if device == .iPhone6sPlus{
kTableHeaderHeight = 300.0
} else if device == .iPhone6 {
kTableHeaderHeight = 300.0
} else if device == .iPhone5s {
kTableHeaderHeight = 225.0
} else if device == .iPhone4s {
kTableHeaderHeight = 200.0
} else if device == .iPhone4 {
kTableHeaderHeight = 200.0
} else if device == .Simulator(.iPhone6sPlus){
kTableHeaderHeight = 300.0
} else {
kTableHeaderHeight = 250.0
}
title = shot.title
//The code for the headerView
headerView = tableView.tableHeaderView
tableView.tableHeaderView = nil
tableView.addSubview(headerView)
tableView.contentInset = UIEdgeInsets(top: kTableHeaderHeight, left: 0, bottom: 0, right: 0)
tableView.contentOffset = CGPoint(x: 0, y: -kTableHeaderHeight)
}
以及updateHeaderView的代码
func updateHeaderView(){
var headerRect = CGRect(x: 0, y: -kTableHeaderHeight, width: tableView.bounds.width, height: kTableHeaderHeight)
if tableView.contentOffset.y < -kTableHeaderHeight {
headerRect.origin.y = tableView.contentOffset.y
headerRect.size.height = -tableView.contentOffset.y
}
headerView.frame = headerRect
}
如果我用这个方法
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return kTableHeaderHeight
}
它会给出一些奇怪的2个标题。。我不能发布这张照片,因为我已经超过了链接限制
提前谢谢
雅利安人
请检查您的表格标题大小。我已经用与headerView相关的所有方法编辑了这个问题,因为我实现了stretchy headerView@Sourave,即使我去掉了stretchy header方法,我仍然会遇到这个问题@sourav和我的tableHeaderSize因设备类型而异。@Aryan Kashyap,我无法得到你想要的东西。所有2幅图像看起来都正常(第一幅有数据,第二幅没有数据)。这意味着什么“tableView在注释开始之前在单元格完成。”(你怎么知道你的tableView没有在那里结束?)我的意思是,如果没有注释,tableView会留下很大的空白,但我希望tableView在注释开始显示之前在单元格完成。。如果他们没有意见@SOURAV请检查您的表格标题大小。我已经使用与headerView相关的所有方法编辑了问题,因为我实现了stretchy headerView@SOURAVE即使我放弃了stretchy header方法,我仍然会遇到这个问题@sourav和我的tableHeaderSize因设备类型而异。@Aryan Kashyap,我无法得到你想要的东西。所有2幅图像看起来都正常(第一幅有数据,第二幅没有数据)。这意味着什么“tableView在注释开始之前在单元格完成。”(你怎么知道你的tableView没有在那里结束?)我的意思是,如果没有注释,tableView会留下很大的空白,但我希望tableView在注释开始显示之前在单元格完成。。如果他们没有意见@苏拉夫
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return kTableHeaderHeight
}