我在TableViewCell中有一个按钮,重叠了欢迎TableViewCell。视图加载时看起来很好,但是当我向下滚动桌面视图并向上滚动时,按钮会被下一个tableviewcell切断。
我找到了一个hack来使消息TableViewCell的背景清晰,但是,按钮的底部仍然无法点击。
有没有办法将按钮的优先级设置在下一个按钮之上?
HomeTableViewController.swift
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "heroCell", for: indexPath) as! HeroTableViewCell
heroCell = cell
cell.separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "welcomeCell", for: indexPath) as! WelcomeTableViewCell
// Set Intro Name
if let user = Auth.auth().currentUser {
// User is signed in
// References to firebase
let userFS = Firestore.firestore().collection("users")
// Set the navigation title to users name
userFS.document(user.uid).getDocument { (document, error) in
if let userInfo = document {
let firstName = userInfo["firstName"] as! String
cell.introLabel.text = "Hey, \(firstName)"
} else {
print("User name does not exist")
}
}
}
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "tripsCell", for: indexPath) as! TripTableViewCell
return cell
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "suggestionsCell", for: indexPath) as! SuggestionTableViewCell
return cell
default:
let cell = tableView.dequeueReusableCell(withIdentifier: "popularsCell", for: indexPath) as! PopularTableViewCell
return cell
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0: return 425
case 1: return 200
case 2: return 400
case 3: return 400
default: return 400
}
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 425
}
HeroTableViewCell.swift
class HeroTableViewCell: UITableViewCell {
// MARK: - Outlets
@IBOutlet weak var heroImage: UIImageView!
@IBOutlet weak var heroImageViewTopConstraint: NSLayoutConstraint!
@IBOutlet weak var planTripButton: SpringButton!
// MARK: - Variables
let notification = UINotificationFeedbackGenerator()
override func awakeFromNib() {
}
// MARK: - Actions
@IBAction func addTripButtonPressed(_ sender: UIButton) {
planTripButton.animation = "pop"
planTripButton.animate()
notification.notificationOccurred(.success)
}
}