Search This Blog

Thứ Sáu, 15 tháng 9, 2017

Tạo class protocol in IOS

- class TableView

protocol CateViewControllerDelegate:class{
    func CateViewController_Selected(modelSelected:ModelNews)
   

}



func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
       if( mdPost.m_type == .PictureSlider) {
                    
                    let cell = tableView.dequeueReusableCell(withIdentifier:           "SlideImageCollectionCell", for: indexPath) as! SlideImageCollectionCell
                    cell.arrPost  = mdPost.m_childs
                    cell.setupViews()
                    cell.contentView.backgroundColor = UIColor.groupTableViewBackground
                   
                    cell.didSelectNews = { (md:ModelNews) -> () in
                        self.delegate?.CateViewController_Selected(modelSelected: md)
                    }
                    return cell
          }
                

        }

- Class main :

extension MainViewController : CateViewControllerDelegate {
    func CateViewController_Selected(modelSelected:ModelNews) {

        self.navigationController?.setNavigationBarHidden(false, animated: true)
        self.segmentControl.snp.removeConstraints()
        self.segmentControl.snp.makeConstraints { (make) -> Void in
            make.width.equalTo(self.view)
            make.height.equalTo(Configs.HEIGHT_TOP_HOrizontalSelection)
            make.top.equalTo(self.view).offset(0)
        }

        self.gotoDetailVC(md: modelSelected)

        
    }

Không có nhận xét nào:

Đăng nhận xét