2016-11-22 1 views
0

У меня есть рабочий UITableView с ячейками самого высокого качества (UITableViewAutomaticDimension) с новостью. И это работает так, как должно было :)Возможно ли, чтобы UITableView включал некоторые ячейки собственного размера и пользовательские ячейки высоты?

И теперь я прихожу к той части, где мне нужно добавить одну ячейку в середине ячеек новостей, а ее высота должна быть того же размера, что и экран устройства.

Я попытался с добавлением этого метода высоты от UITableView класса:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    let item = feed[indexPath.row] 
    if item is News { 
     return UITableViewAutomaticDimension 
    } else if item is ConfigurationBit { 
     return view.bounds.size.height 
    } 
    return 0.0 
} 

, но это не дает правильный результат. Есть ли у вас какие-либо предложения?

ОБНОВЛЕНИЕ Следующий код является правильным. Проблема была в другом месте, и это не имело никакого отношения к этому делу.

+0

newsHandler.feed этот массив, содержащий как Новости и ConfigurationBit объекты – Vinodh

+0

да. Я отредактировал его, так что теперь он стал менее запутанным. –

+0

ваш код в порядке, пусть распечатать view.bounds.size.height, чтобы увидеть его правильный размер или нет. – Nick

ответ

0

Я думаю, что вам не хватает, чтобы установить rowHeight и estimatedRowHeight для Tableview .Please найти код я использовал

var arrayOfCellData = [Any]() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     arrayOfCellData = [cellData(cell : 1, text : "asdadas", image : #imageLiteral(resourceName: "mark")), 
          cellconfigData(cell : 2, text : "dasdadad", image : #imageLiteral(resourceName: "mark")), 
          cellData(cell : 3, text : "asraerqsadas", image : #imageLiteral(resourceName: "mark")), 
          cellconfigData(cell : 4, text : "asraerqsadas", image : #imageLiteral(resourceName: "mark")), 
          cellData(cell : 5, text : "asraerqsadas", image : #imageLiteral(resourceName: "mark")), 
          cellconfigData(cell : 6, text : "asraerqsadas", image : #imageLiteral(resourceName: "mark"))] 
     tableView.rowHeight = UITableViewAutomaticDimension 
     tableView.estimatedRowHeight = 245 
    } 


    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return arrayOfCellData.count 
    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let item = arrayOfCellData[indexPath.row] 
     if item is cellData{ 
      let cell = Bundle.main.loadNibNamed("OwnTableViewCell", owner: self, options: nil)?.first as! OwnTableViewCell 

      cell.mainImageView.image = (arrayOfCellData[indexPath.row] as! cellData).image 
      cell.mainLabel.text = (arrayOfCellData[indexPath.row] as! cellData).text 
      return cell 
     } 
     else 
     { 
      let cell = Bundle.main.loadNibNamed("NewTableViewCell", owner: self, options: nil)?.first as! NewTableViewCell 

      cell.mainImageView.image = (arrayOfCellData[indexPath.row] as! cellconfigData).image 
      cell.mainLabel.text = (arrayOfCellData[indexPath.row] as! cellconfigData).text 

      return cell 
     } 
    } 

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     let item = arrayOfCellData[indexPath.row] 

     if item is cellData{ 
      return UITableViewAutomaticDimension 
     } 
     else if item is cellconfigData{ 
      return 100 
     } 
     return 0.0 
    } 
0
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    let item = feed[indexPath.row] 
    if item is News { 
     let cell = self.tableView(tableObject, cellForRowAt indexPath: indexPath) 
     return cell.frame.size.height 
    } else if item is ConfigurationBit { 
     return view.bounds.size.height 
    } 
    return 0.0 
} 
Смежные вопросы