Search This Blog

Hiển thị các bài đăng có nhãn TableView. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn TableView. Hiển thị tất cả bài đăng

Thứ Tư, 12 tháng 9, 2018

Trượt đến cuối khung chat


@objc internal func scrollToBottom(_ animated: Bool = false) {
        let boundsHeight = collectionView?.bounds.size.height ?? 0
        let sizeHeight = collectionView?.contentSize.height ?? 0
        let offset = CGPoint(x: 0, y: max(sizeHeight - boundsHeight, 0))
        collectionView?.setContentOffset(offset, animated: animated)
        scrollToBottomButtonIsVisible = false
    }

Thứ Sáu, 24 tháng 8, 2018

Làm mới lại khi chọn 1 dòng trong table view in ios


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

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

Thứ Hai, 1 tháng 1, 2018

Chèn thêm khung delete bên phải cell TableView in IOS

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        
      
            return true
        
        
    }
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        
        if editingStyle == .delete {
            if((self.arrNews.count) > 0 ){
                let mdPost = arrNews[indexPath.row] as! ModelNews
                DataManager.deleteToBookmarkOnlyData(md: DataManager.getByIdBookmarkOnlyData(id_news: mdPost.m_object_id!))
                self.reloadData()
            }
        }

    }

Thứ Ba, 26 tháng 12, 2017

Áp sự kiện click cho 1 cell in IOS

 cell.didSelectNews = { (md:ModelNews) -> () in
                        (self.delegate?.CateViewController_Selected(modelSelected: [md]))!

                    }


// trong class cell 

open var didSelectNews: ((_ md: ModelNews ) -> ())?

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        if let mdGet = arrPost?[indexPath.item]  {
            let mdPost = mdGet as! ModelNews
            didSelectNews!(mdPost)
        }
}

Thứ Ba, 7 tháng 11, 2017

Thứ Năm, 2 tháng 11, 2017

Ẩn tableview in ios


 mCollection.isHidden = true

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)

        
    }

Thứ Tư, 16 tháng 8, 2017

Table trong ios Nang cao 1


//  so dong 
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return mang.count ;
   }
    
//  giao dien moi dong
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! DongTableViewCell
        
        cell.lblDong.text = mang[indexPath.row].Ten
        cell.imvdongHinh.image = UIImage( named: mang[indexPath.row].Hinh )
        
        return cell
        
    }
    
    //  su kien click vao item
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print( indexPath.row )
        
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let manhinh = sb.instantiateViewController(withIdentifier: "ManHinhChiTiet") as! ChiTietViewController
        manhinh.hinh = mang[indexPath.row].Hinh
        
        self.navigationController?.pushViewController(manhinh, animated: true)
        

    }

Table view trong IOS

// them thu vien

class ViewController:  UITableViewDataSource , UITableViewDelegate{}


// tạo mảng , khai bao table , dat id cho cell
 var mang:[String]!
    

 @IBOutlet weak var tableDanhSach: UITableView!

// trong ham khoi tao 
 override func viewDidLoad() {
        super.viewDidLoad()
        mang = ["Nhut", "Nam", "Tuan"]
        tableDanhSach.dataSource = self

     tableDanhSach.delegate = self

    }


// them 2 hàm 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3 ;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
        cell?.textLabel?.text = "Nhut"
        
        return cell!
        
    }