2016-07-23 3 views
0

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

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
     if indexPath.row != 0 { 
      cell.contentView.backgroundColor = UIColor.clearColor() 
      var whiteRoundedCornerView: UIView = UIView(frame: CGRectMake(10, 10, 365, 250)) 
      whiteRoundedCornerView.backgroundColor = UIColor.lightGrayColor() 
      whiteRoundedCornerView.layer.masksToBounds = false 
      whiteRoundedCornerView.layer.cornerRadius = 20 
      whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(-0, -1) 
      whiteRoundedCornerView.layer.shadowOpacity = 0.1 

      cell.contentView.addSubview(whiteRoundedCornerView) 
      cell.contentView.sendSubviewToBack(whiteRoundedCornerView) 
     } 


    } 
+2

Почему у вас есть 'if indexPath.row! = 0'? – kabiroberai

+0

В этом случае я отправлю его в качестве ответа, чтобы другие люди могли видеть, что вопрос был решен – kabiroberai

ответ

0

Проблема в вашем коде - это заявление if. Когда indexPath.row равно 0 (это первая строка), ваш код конфигурации не выполняется. Чтобы решить эту проблему, просто удалите оператор if из вашего кода. Он должен выглядеть примерно так:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    cell.contentView.backgroundColor = UIColor.clearColor() 
    var whiteRoundedCornerView: UIView = UIView(frame: CGRectMake(10, 10, 365, 250)) 
    whiteRoundedCornerView.backgroundColor = UIColor.lightGrayColor() 
    whiteRoundedCornerView.layer.masksToBounds = false 
    whiteRoundedCornerView.layer.cornerRadius = 20 
    whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(-0, -1) 
    whiteRoundedCornerView.layer.shadowOpacity = 0.1 

    cell.contentView.addSubview(whiteRoundedCornerView) 
    cell.contentView.sendSubviewToBack(whiteRoundedCornerView) 
} 
Смежные вопросы