面对这个问题。不要从服务器下载将数据加载到单元格和部分。当我在方法中指出
numberOfRowsInSection部分
数组PFOject userInformation.count。我没有在标题中加载数据。 提示我指出如何执行此操作。但是我不明白如何写下将数据加载到TableviewCell和section标头中的方法。
var detailUserInfo = InfoMy()
请帮助并告诉我该怎么做。我将非常感谢...
import UIKit
import MessageUI
import Parse
class InfoViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,MFMailComposeViewControllerDelegate{
var userInformation = [InfoMy]()
var detailUserInfo = InfoMy()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
detailUserInfo.fetchInBackground()
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController!.view.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.backgroundColor = UIColor.clear
navigationController?.navigationBar.tintColor = UIColor.universalColorYellow
let sendButton = UIButton(frame: CGRect(x: 0, y: 0, width: 9, height: 12))
sendButton.setBackgroundImage(UIImage(named: "send"), for: .normal)
sendButton.addTarget(self, action: #selector(sendMessage), for: .touchUpInside)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: sendButton)
let smileButton = UIButton(frame: CGRect(x: 0, y: 0, width: 9, height: 12))
smileButton.setBackgroundImage(UIImage(named: "smile1"), for: .normal)
smileButton.setBackgroundImage(UIImage(named: "like2"), for: .selected)
smileButton.addTarget(self, action: #selector(leftNavigationLikeButton), for: .touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: smileButton)
//title = detailSoccer.detailTitleS
let nib: UINib = UINib(nibName: "HeaderViewProfileMy", bundle: nil)
tableView.register(nib, forHeaderFooterViewReuseIdentifier: "ContactTableViewCell")
tableView.tableFooterView = UIView(frame: .zero)
tableView.estimatedRowHeight = 280
tableView.rowHeight = UITableViewAutomaticDimension
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
loadMatchSoccer()
tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 40))
imageView.contentMode = .scaleAspectFit
let image = UIImage(named: "forecast2")
imageView.image = image
navigationItem.titleView = imageView
}
@objc func leftNavigationLikeButton() {
let header = ContactTableViewCell()
let qwery = InfoMy(withoutDataWithClassName: "InfoMy", objectId: "PIorJ43dRq")
var countLike = qwery.likeCount
countLike += 1
qwery.setObject(countLike, forKey: "likeCount")
qwery.saveInBackground { (object, error) in
if error == nil {
print("error")
} else {
header.likeCountProfile?.text = "\(self.detailUserInfo.likeCount)"
self.tableView.reloadData()
}
}
}
func showSendMailErrorAlert() {
let alert = UIAlertController(title: "BRAVOBET", message: "Настройте вашу почту на телефоне", preferredStyle: .alert)
// alert.addAction(UIAlertAction(title: "Да", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "ОК", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
@objc func sendMessage() {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["a.ilyin007@gmail.com"])
mailComposerVC.setSubject("Укажите вашу тему вопроса")
mailComposerVC.setMessageBody("Напишите свой вопрос, в течении 24ч. я Вам отвечу!", isHTML: false)
return mailComposerVC
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 300
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ContactTableViewCell") as! ContactTableViewCell
header.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300)
header.nameUserProfile.text = detailUserInfo.name
header.likeCountProfile?.text = "\(detailUserInfo.likeCount)"
header.sendMessageCount.text = "\(detailUserInfo.messangeCount)"
if header.userMyFoto.image != nil {
header.userMyFoto.image = UIImage(named: "avatar-pic")
}
detailUserInfo.imageProfile.getDataInBackground { (data, error) in
header.userMyFoto.image = error == nil ? UIImage(data: data!) : nil
}
return header
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let infoCell = tableView.dequeueReusableCell(withIdentifier: "infoCell") as! InfoTableViewCell
infoCell.titleProfile.text = "Профиль"
infoCell.infogdevice.text = detailUserInfo.myinfo
return infoCell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func loadMatchSoccer() {
let qwery = InfoMy.query() as! PFQuery<InfoMy>
qwery.findObjectsInBackground { (object, error) in
if error == nil {
self.userInformation = object!
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
} else {
print(error!)
}
}
}
}