現在、UdemyでSNSアプリ開発をしているのですが、二つのエラーに悩まされています。
1つ目はセルの高さがおかしい、
2つ目は左上のUIImageViewが画像を反映しない
です。実は一つ目は、二つ目のエラーのときに一度全ての部品を消して再結合したのですが、それっきり全く別のエラー(1つ目のエラー)に切り替わり、非常に悩まされています。コードは全て成功し、問題はHomeViewControllerと、HomeTableViewCellだとはわかっているのですが、コードとControllerとセルの関係?がよく分からず全く先に進めそうにありません。
オートレイアウトの調整や、TableViewCellの高さを440にしたのですが、全く変わりません。
もはや手がつけられない状態なので、誰か助けてください。お願いします!!
2020-02-04 11:07:41.394743+0900 OriginalInstagram[3024:108697] - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist 2020-02-04 11:07:41.569348+0900 OriginalInstagram[3024:108705] 6.15.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60201000 started 2020-02-04 11:07:41.570445+0900 OriginalInstagram[3024:108705] 6.15.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r) 2020-02-04 11:07:41.892451+0900 OriginalInstagram[3024:108719] 6.15.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled 2020-02-04 11:07:44.907799+0900 OriginalInstagram[3024:108529] [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <OriginalInstagram.HomeTableViewCell: 0x7f83d0441440; baseClass = UITableViewCell; frame = (0 28; 375 440); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x600003d46020>> 2020-02-04 11:11:41.801701+0900 OriginalInstagram[3024:109665] [] nw_connection_receive_internal_block_invoke [C1] Receive reply failed with error "Operation canceled" 2020-02-04 11:11:41.802042+0900 OriginalInstagram[3024:109665] [] nw_connection_receive_internal_block_invoke [C1] Receive reply failed with error "Operation canceled" 2020-02-04 11:11:41.802275+0900 OriginalInstagram[3024:109665] [] nw_connection_receive_internal_block_invoke [C1] Receive reply failed with error "Operation canceled" 2020-02-04 11:11:41.802612+0900 OriginalInstagram[3024:109665] [] nw_connection_receive_internal_block_invoke [C1] Receive reply failed with error "Operation canceled"``` ```ここに言語を入力 import UIKit import FirebaseAuth import FirebaseDatabase import SDWebImage class HomeViewController: UIViewController { var posts = [Post]() var users = [User]() @IBOutlet weak var tableView: UITableView! 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 { self.fetchUser(uid: uid) { self.posts.append(newPost) self.tableView.reloadData() } } } } } 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 } } ``````ここに言語を入力 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! 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 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 04:02
2020/02/04 05:36 編集