2016-03-08 61 views
0

大家好,所以我一直在iOS最近處理UITableViews。我的UITableView返回一些奇怪的結果..UITableView返回奇怪的大小

一些照片顯示

Then The first cell is so big.

Then the 2nd Cell looks like this

這些所有的細胞大小不同而不同..

以及類代碼是這樣嗎

import UIKit 
    import FLAnimatedImage 

    class ShotDetailTableViewController: UITableViewController { 


     @IBOutlet weak var bgImageView: FLAnimatedImageView! 

     @IBOutlet weak var viewsCount: UILabel! 
     @IBOutlet weak var likesCount: UILabel! 
     @IBOutlet weak var commentsCount: UILabel! 

     @IBOutlet weak var avatarImageView: UIImageView! 
     @IBOutlet weak var usernameLabel: UILabel! 
     @IBOutlet weak var descriptionLabel: UILabel! 

     @IBOutlet weak var reboundCount: UILabel! 
     @IBOutlet weak var attachmentCount: UILabel! 

     @IBOutlet weak var tagsCollectionView: UICollectionView! 
     @IBOutlet weak var reboundCollectionView: UICollectionView! 
     @IBOutlet weak var attachmentCollectionView: UICollectionView! 

     @IBOutlet weak var commentTableView: UITableView! 

     var shots : [Shot] = [Shot]() 
     var comments : [Comment] = [Comment]() 
     var shot : Shot! 

     var reboundPages = 1 
     var attachmentPages = 1 

     override func viewDidLoad() { 
      super.viewDidLoad() 

      title = shot.title 

      bgImageView.sd_setImageWithURL(NSURL(string: shot.imageUrl), placeholderImage: UIImage(named: "1"), options: .ContinueInBackground) 

      viewsCount.text = "\(shot.viewsCount)" 
      likesCount.text = "\(shot.likesCount)" 
      commentsCount.text = "\(shot.commentCount)" 

      avatarImageView.sd_setImageWithURL(NSURL(string: shot.user.avatarUrl), placeholderImage: UIImage(named: "2")) 

      usernameLabel.text = "\(shot.user.username)" 
      descriptionLabel.text = "\(shot.description)" 

      reboundCount.text = "\(shot.reboundCount)" 
      attachmentCount.text = "\(shot.attachmentsCount)" 

      commentTableView.delegate = self 
      commentTableView.dataSource = self 
      commentTableView.estimatedRowHeight = 100.0; 
      commentTableView.rowHeight = UITableViewAutomaticDimension; 
      commentTableView.separatorStyle = UITableViewCellSeparatorStyle.None 

      let api = DribbleObjectHandler() 
      api.loadComments(shot.commentsUrl, completion:didLoadComments) 

      NSUserDefaults.standardUserDefaults().setValue(true, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable") 
     } 


    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
     if tableView == commentTableView { 
     return UITableViewAutomaticDimension 
     } else { 
     return UITableViewAutomaticDimension 
     } 
    } 

     override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 
      avatarImageView.clipsToBounds = true 
      avatarImageView.layer.cornerRadius = 25 

      self.commentTableView.reloadData() 
     } 

     func didLoadComments(comments : [Comment]){ 
      self.comments = comments 
      self.commentTableView.reloadData() 
     } 

     // MARK: - Table view data source 

     override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
      // #warning Incomplete implementation, return the number of sections 
     if tableView == commentTableView { 
      return 1 
     } else { 
      return 1 
     } 
     } 

     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
      // #warning Incomplete implementation, return the number of rows 
      if tableView == commentTableView { 
       return comments.count 
      } else { 
      return super.tableView(tableView, numberOfRowsInSection: section) 
      } 
     } 

     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
      if tableView == commentTableView { 
      let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CommentCell 

      // Configure the cell... 
       let comment = comments[indexPath.row] 

       //cell.nameLabel.text = comment.user.name 
       // cell.commentLabel.text = comment.body 

       //cell.avatarImageView.sd_setImageWithURL(NSURL(string: comment.user.avatarUrl), placeholderImage: UIImage(named: "2")) 
       cell.avatarImageView.image = UIImage(named: "2") 

       return cell 

      } else { 
       let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) 
       return cell 
      } 
     } 
     override func didReceiveMemoryWarning() { 
      super.didReceiveMemoryWarning() 
      // Dispose of any resources that can be recreated. 
     } 

    } 

當我實現heightForRowAtIndexPath了的tableView變得非常小 不幸的是,我不能放超過2個鏈接..所以我不能顯示圖片 和我沒有得到任何錯誤日誌中

我試圖找到與此相關的問題,但可能真的找不到多少。

由於提前 雅利安

回答

1

嘗試,而不是實施estimatedHeightForRowAtIndexPath,實現heightForRowAtIndexPath

+0

不..它沒有。 –

+0

@AryanKashyap你是無知的,或者你不理解答案。您的數據源代理中沒有'heightForRowAtIndexPath'(所顯示的代碼),因此「不..」不是合適的註釋(不確定前面的註釋是否已被刪除,如果是,請道歉我的咆哮)。 –

+0

我很抱歉關於粗魯我的意思是我曾嘗試實現它,但它仍然是相同的。 –