2017-02-02 4 views
1

Требование:UIImageView на TableViewCell отсутствует свои ограничения на щелкая клетку

Я делаю sideBar navigation, используя UITableView и UITableViewCell внутри it.Inside UITableViewCell, есть UIImageView и через UILabel .i хотят UIImageView к есть такие же высота и ширина, и я дал ограничения для этого.

Выпуск:

НО после нажатия на каждую ячейку, размер ImageView ИЗМЕНЕНИЯ (СДЕРЖИВАЮЩИЕ отсутствующий) и перекрывал LABEL.

Я сделал все ограничения только в раскадровке, и я делаю в быстром 3 , пожалуйста, помогите мне.

Код работы:

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

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell 
    cell.label.text = data[indexPath.row] 
    let iconName = images[indexPath.row] 
    //print("\(iconName)") 
    let image = UIImage(named: iconName) 
    // print("The loaded image: \(image)") 
    cell.imageViews.image = image 

     return cell 
} 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    tableView.deselectRow(at: indexPath, animated: true) 
} 

Screent Выстрел

At the time of loading

On clicking each cell

constraints on images

+0

Показать, что вы сделалиSelectForRow, если реализовано? – Himanshu

+0

cell.imageView.maskToBound = верно, попробуйте этот –

+0

@Himanshu Func Tableview (_ Tableview: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow (по адресу: indexPath, анимированные: истина) } –

ответ

0
 for viw in cell.contentView.subviews { 
     if ((viw as? UIImageView) != nil) { 
      viw.removeFromSuperview() 
     }else if ((viw as? UILabel) != nil) { 
      viw.removeFromSuperview() 
     } 
    } 

Используйте этот код после создания ячейки [со второй строки]. Попробуй.

Смежные вопросы