SNSアプリ開発で、ビルドには成功したのですが、下記の画像のようにセルが小さくなってしまいました。
セルの高さは440にしているはずなのですが、、、
コードに異常はないようなのですが、なぜこうなったのか見当がつきません。
もし原因が分かる方がいたら教えてください。お願いします。
HomeViewController.swift
import UIKit import FirebaseAuth import FirebaseDatabase import SDWebImage class HomeViewController: UIViewController { @IBOutlet weak var tableView: UITableView! var posts = [Post]() var users = [User]() override func viewDidLoad() { super.viewDidLoad() tableView.estimatedRowHeight = 440 tableView.rowHeight = UITableViewAutomaticDimension tableView.dataSource = self loadPost() } func loadPost() { Database.database().reference().child("posts").observe(.childAdded) { (snapshot: DataSnapshot) in if let dict = snapshot.value as? [String: Any] { let newPost = Post.transformPost(dict: dict) if let uid = newPost.uid { // uidのチェック self.fetchUser(uid: uid) { self.posts.append(newPost) self.tableView.reloadData() } } } } } @IBAction func button_TouchUpInside(_ sender: Any) { self.performSegue(withIdentifier: "commentSegue", sender: nil) } func fetchUser(uid: String, completed: @escaping () -> Void){ Database.database().reference().child("users").observeSingleEvent(of: DataEventType.value) { snapshot in if let dict = snapshot.value as? [String: Any] { let user = User.transformUser(dict: dict) self.users.append(user) completed() } } } // ログアウトする @IBAction func logout_TouchUpInside(_ sender: Any) { do { try Auth.auth().signOut() } catch let logoutError { print(logoutError) } print(Auth.auth().currentUser as Any) let storyboard = UIStoryboard(name: "Start", bundle: nil) let signInVC = storyboard.instantiateViewController(withIdentifier: "SignInViewController") self.present(signInVC, animated: true, completion: nil) } } extension HomeViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return posts.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! HomeTableViewCell let post = posts[indexPath.row] let user = users[indexPath.row] cell.post = post cell.user = user return cell } }
HomeTableViewCell.swift
import UIKit import FirebaseDatabase class HomeTableViewCell: UITableViewCell { @IBOutlet weak var profileImageView: UIImageView! @IBOutlet weak var nameLabel: UILabel! @IBOutlet weak var postImageView: UIImageView! @IBOutlet weak var likeImageView: UIImageView! @IBOutlet weak var commentImageView: UIImageView! @IBOutlet weak var shareImageView: UIImageView! @IBOutlet weak var likeCountButton: UIButton! @IBOutlet weak var captionLabel: UILabel! @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView! var post: Post? { didSet { updateView() } } var user: User? { didSet { setupUserInfo() } } func updateView(){ captionLabel.text = post!.caption if let photoUrlString = post!.photoUrl { let photoUrl = URL(string: photoUrlString) postImageView.sd_setImage(with: photoUrl) } // setupUserInfo() } func setupUserInfo() { nameLabel.text = user?.username if let photoUrlString = user?.profileImageUrl { let photoUrl = URL(string: photoUrlString) profileImageView.sd_setImage(with: photoUrl, placeholderImage: UIImage(named: "placeholderImg")) } } override func awakeFromNib() { super.awakeFromNib() // Initialization code if nameLabel?.text != nil { nameLabel.text = "" return } if captionLabel?.text != nil { captionLabel.text = "" return } // nameLabel.text = "" // captionLabel.text = "" } override func prepareForReuse() { super.prepareForReuse() profileImageView.image = UIImage(named: "placeholderImg") } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/02/04 23:25
2020/02/05 02:54