很抱歉,如果重复的话。我试图用SO复习类似的问题-仍然不能完全让我理解如何处理。
我有一个tableView,三个textViews和一个UIButton。当用户滚动tableView时,tableView应该将textFields和按钮推出图像,并占用更多空间。完成后,我要继续滚动浏览单元格。
(我希望textFields之一始终保留并仍然显示标题。)
我认为我需要在tableView标头内的tableView上方放置textViews和按钮,之后我需要在tableView上方的UIView和tableView本身之间设置某些约束。然后,我需要使用UIScrollViewDelegate并进行计算。
你们可能知道,我在编程方面相对较新,我相信这就是为什么我不太了解相关问题的原因。正如您可能也可以说的那样,为什么我对如何解决我的问题感到非常困惑!
我不想使用tableView并覆盖'AddNewPersonBtn'和底部的两个textView-在屏幕上仅保留顶部的textView,navigationBar和tableView。 ->在您再次向下滚动之前,其余的将再次可见。
这是VC的代码:
import UIKit
import RealmSwift
class AllPersonsInYourDiary: UIViewController, UITableViewDelegate, UITableViewDataSource {
var diary: Diaries?
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var showingDiaryName: UILabel!
@IBOutlet weak var showingDiaryQuestion: UILabel!
@IBOutlet weak var showingExtraIdentifer: UILabel!
@IBOutlet weak var diaryTheme: UIImageView!
@IBOutlet weak var diaryPhoto: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.tableFooterView = UIView()
self.tableView.tableHeaderView = UIView()
}
override func viewWillAppear(_ animated: Bool) {
tableView.reloadData()
showDiaryIdentifiers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func createNewPersonButton () {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier:
"PersonViewController") as! PersonViewController
controller.mode = .create
controller.diary = diary
self.navigationController?.pushViewController(controller, animated: true)
}
@IBAction func showEditFunc () {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SettingsVC") as! SettingsVC
controller.diary = diary
self.navigationController?.pushViewController(controller, animated: true)
}
func showDiaryIdentifiers () {
self.showingDiaryName.text = diary?.diaryName
self.showingDiaryQuestion.text = diary?.diaryQuestion
self.showingExtraIdentifer.text = diary?.diaryExtraIdentifier
self.diaryTheme.image = UIImage(data: diary?.diaryTheme ?? Data()) ?? UIImage(named: "Blank")
// self.diaryPhoto.image = UIImage(data: diary?.diaryPhoto ?? Data ()) ?? UIImage(named: "Blank")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return diary!.people.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Person1", for: indexPath) as! PersonCell
let date = DateFormatter.localizedString(from: (diary?.people[indexPath.row].dateCreated)!, dateStyle: .short, timeStyle: .none)
cell.personName.text = diary?.people[indexPath.row].name
cell.personAnswer.text = date
cell.personPhoto.image = UIImage(data: diary?.people[indexPath.row].photo ?? Data()) ?? UIImage(named: "PortaitPhoto")
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier:
"PersonViewController") as! PersonViewController
controller.person = diary?.people[indexPath.row]
controller.diary = diary
controller.mode = .show
self.navigationController?.pushViewController(controller, animated: true)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let alert = UIAlertController(title: "Are you sure you wish to delete person?", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "No thanks!", style: .cancel)
let action1 = UIAlertAction(title: "Delete!", style: .destructive, handler: { _ in
let realm = try! Realm()
try! realm.write {
guard let person = self.diary?.people[indexPath.row] else {
return
}
self.diary!.people.remove(at: indexPath.row)
realm.delete(person)
}
tableView.deleteRows(at: [indexPath], with: .fade)
})
alert.addAction(action)
alert.addAction(action1)
present(alert, animated: true)
} }
}