在初始加载时删除UITableViewCell的右侧阴影

多米尼克·贝克(Dominic Baker)

我正在尝试创建卡片类型的布局,并在这里使用了许多答案以获取当前的解决方案。我正在使用Swift 2和XCode 7.3.1。

首次应用加载

拉后刷新

UITableViewCell代码为:

func addShadow() {
  cardView.layer.shadowPath = UIBezierPath(rect: cardView.bounds).CGPath
  cardView.layer.shadowOpacity = 0.7
  cardView.layer.shadowOffset = CGSizeZero
  cardView.layer.shadowRadius = 2
  cardView.layer.masksToBounds = false
}

override func layoutSubviews() {
  addShadow()
}

为什么单元格仅在拉动刷新后才看起来正确,并且事先在右侧有多余的阴影?

编辑:

我也添加了TableViewController

class BusinessTableViewController: PFQueryTableViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    navigationController!.navigationBar.translucent = false
    navigationController?.toolbar.translucent = false
    configureTable()
    // Do any additional setup after loading the view.
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  func configureTable() {
    tableView.tableFooterView = UIView(frame: CGRectZero)
    tableView.backgroundColor = Utility.tableBackgroundColor
  }

  override func queryForTable() -> PFQuery {
    let query = PFQuery(className: "Business")
    query.cachePolicy = .NetworkElseCache
    query.orderByAscending("createdAt")
    return query
  }

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
    let cell = tableView.dequeueReusableCellWithIdentifier("businessCell", forIndexPath: indexPath) as! BusinessCell
    cell.layoutIfNeeded()

    let business = object as! Business
    cell.nameLabel.text = business.name
    var categoryString = ""

    for cat in business.categories {
      categoryString += cat

      if cat != business.categories.last {
        categoryString += ", "
      }
    }

    // Image setup
    if cell.mainImageView.layer.cornerRadius != 3 {
      cell.mainImageView.layer.cornerRadius = 3
      cell.mainImageView.clipsToBounds = true
      cell.mainImageView.layer.frame = CGRectInset(cell.mainImageView.layer.frame, 60, 60)
      cell.mainImageView.layer.borderColor = UIColor.purpleColor().CGColor
      cell.mainImageView.layer.borderWidth = 2.0
    }
    let imageFile = business.displayImage
    cell.mainImageView.file = imageFile
    cell.mainImageView.loadInBackground()

    // Button steup
    let defaultAttributes = [
      NSFontAttributeName: UIFont.fontAwesomeOfSize(15),
      NSForegroundColorAttributeName: UIColor.grayColor()]
    let activeAttributes = [
      NSFontAttributeName: UIFont.fontAwesomeOfSize(15),
      NSForegroundColorAttributeName: UIColor.blueColor()]

    cell.bookmarkButton.setTitleTextAttributes(defaultAttributes, forState: .Normal)
    cell.bookmarkButton.title = "\(String.fontAwesomeIconWithName(.BookmarkO)) Bookmark"

    let bookmarkQuery = PFQuery(className: "Bookmark")
    bookmarkQuery.whereKey("business", equalTo: business)
    bookmarkQuery.whereKey("user", equalTo: User.currentUser()!)
    bookmarkQuery.cachePolicy = .NetworkElseCache
    bookmarkQuery.countObjectsInBackgroundWithBlock { (count, error) in
      if error == nil && count > 0 {
        cell.bookmarkButton.setTitleTextAttributes(activeAttributes, forState: .Normal)
        cell.bookmarkButton.title = "\(String.fontAwesomeIconWithName(.Bookmark)) Bookmark"
      }
    }

    cell.phoneButton.setTitleTextAttributes(defaultAttributes, forState: .Normal)
    cell.phoneButton.title = "\(String.fontAwesomeIconWithName(.Phone)) Call"
    if business.phone == "" {
      cell.phoneButton.enabled = false
    }
    cell.reviewButton.setTitleTextAttributes(defaultAttributes, forState: .Normal)
    cell.reviewButton.title = "\(String.fontAwesomeIconWithName(.MapMarker)) Directions"

    return cell
  }

  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row + 1 > self.objects?.count {
      return 44
    }

    let height = super.tableView(tableView, heightForRowAtIndexPath: indexPath)
    return height
  }

  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row >= self.objects?.count {
      self.loadNextPage()
      tableView.deselectRowAtIndexPath(indexPath, animated: true)
      return
    }

    //performSegueWithIdentifier("viewBusiness", sender: self)
  }

  /*
   // MARK: - Navigation

   // In a storyboard-based application, you will often want to do a little preparation before navigation
   override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
   // Get the new view controller using segue.destinationViewController.
   // Pass the selected object to the new view controller.
   }
   */

}
多米尼克·贝克(Dominic Baker)

我为有相同问题的任何人弄清楚了:

override func awakeFromNib() {
  super.awakeFromNib()
  addShadow()
}

我添加了代码awakeFromNib而不是layoutSubviews

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在初始页面加载时引导数据

来自分类Dev

编辑UITableViewCell时如何删除删除按钮?

来自分类Dev

加载DatePicker时的特定初始日期/时间

来自分类Dev

jQuery在初始页面加载时重新加载javascript资源

来自分类Dev

加载时删除Qt Webkit加载光标

来自分类Dev

UITableViewCell.detailTextLabel在加载时不显示

来自分类Dev

加载时片段初始耗时

来自分类Dev

在显示UIMenucontroller时删除UItableViewcell选择

来自分类Dev

在悬停时,在引导行的右侧显示删除按钮

来自分类Dev

为什么我的自定义UITableViewCell宽度在初始加载时不正确?

来自分类Dev

在CSS中使用列时删除框阴影中断

来自分类Dev

UIViewController初始加载时高度错误

来自分类Dev

“尝试多次加载角度”警告-仅在初始页面加载时

来自分类Dev

UITableViewCell上的阴影效果不佳

来自分类Dev

在初始页面加载时加载目标ajax php文件

来自分类Dev

UITableViewCell:圆角和阴影

来自分类Dev

引导在加载初始ramdisk时停止

来自分类Dev

防止在历史回溯时加载初始数据

来自分类Dev

页面加载时的CSS(框阴影)过渡

来自分类Dev

加载大量初始数据时出现MemoryError

来自分类Dev

加载图像时删除同级

来自分类Dev

加载时删除Qt Webkit加载光标

来自分类Dev

UITableViewCell.detailTextLabel在加载时不显示

来自分类Dev

引导在加载初始ramdisk时停止

来自分类Dev

UITableViewCell在点击时显示删除按钮

来自分类Dev

初始加载时的“流星变化”表单值

来自分类Dev

UITableViewCell contenview 上的阴影率在滚动时增加

来自分类Dev

不要在初始渲染时加载选项

来自分类Dev

初始加载后从数据模型更新 uiTableViewCell

Related 相关文章

热门标签

归档