纯swift实现ipad版简单美团界面功能

2020-01-09 00:06:44王振洲

swift,ipad,美团界面


class XFJLeftViewCell: UITableViewCell {
  //左边的tableView
  class func leftViewCell(tableView : UITableView) ->XFJLeftViewCell {
    //绑定cell类型
    let leftCell = "leftCell"
    var cell = tableView.dequeueReusableCellWithIdentifier(leftCell)
    //判断cell是否为空
    if cell == nil {
      cell = XFJLeftViewCell(style: .Default, reuseIdentifier: leftCell)
    }
    return cell as! XFJLeftViewCell
  }
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    //设置背景图片
    backgroundView = UIImageView(image: UIImage(named:"bg_dropdown_leftpart"))
    selectedBackgroundView = UIImageView(image: UIImage(named:"bg_dropdown_left_selected"))
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

2.1 该方法是在数据源方法中调用的,用来加载cell

3 自定义右边的tableViewCell

 


class XFJRightViewCell: UITableViewCell {
  //右边的tableView
  class func righViewCell(tableView : UITableView) ->XFJRightViewCell {
    //定义cell的标识
    let rightCell = "rightCell"
    //创建cell
    var cell = tableView.dequeueReusableCellWithIdentifier(rightCell)
    //判断
    if cell == nil {
      cell = XFJRightViewCell(style: .Default, reuseIdentifier: rightCell)
    }
    //返回cell
    return cell as! XFJRightViewCell
  }

  //设置cell的背景图片
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    backgroundView = UIImageView(image: UIImage(named: "bg_dropdown_rightpart"))
    selectedBackgroundView = UIImageView(image: UIImage(named:"bg_dropdown_right_selected"))
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

十一 上半部分总结

1 用上面这些方法确实可以达到用户点击item,弹出对应的控制器.但是上面的代码只是写了对其中一个点击item弹出的业逻辑,还有中间的item并没与处理,如果采用这样的方法处理,那么代码量太多了,并且看起来也显得没什么技术含量,我们最终将不会采用这种方法实现.

十二 代理 协议(最终实现的方案)

1 需要实现的功能 : 通过代理协议的方式,实现用户点击弹出控制器的左边部分,显示出右边部分,并且将对应的头像和主标题,子标题显示到item中

2 定义协议方法 : (包括可实现和可不实现)–> 因为 : 当点击左边的tableView中的cell的时候,有右边有些内容是空的,所以如果都定义为必须实现的,会出现问题