Đây là video ghi lại một kỹ năng nhỏ trong buổi học lập trình UITableView của khoá học Lập trình Apple iOS Swift căn bản đến nâng cao.

Mã nguồn ví dụ và nhiều ví dụ nâng cao, bài tập thực hành được chia sẻ tại lớp học. Tuy nhiên, các bạn hoàn toàn có thể code theo video là tạo được.

Học lập trình iOS trực tuyến cơ bản đến nâng cao

Một số chú ý khi lập trình customize UITableViewCell

class CustomCell: UITableViewCell {

    @IBOutlet weak var thumb: UIImageView!
    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var score: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

Phải đăng ký XIB cho custom UITableViewCell

let nibCell = UINib(nibName: "CustomCell", bundle: nil)
self.tableView.registerNib(nibCell, forCellReuseIdentifier: cellID)

Hàm trả về Custom UITableViewCell

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: CustomCell!
        
        if let dequeCell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) as? CustomCell {
            cell = dequeCell
        }
        let poster = data[indexPath.row]
        cell.title.text = poster.title
        cell.thumb.image = poster.image
        cell.score.text = "(poster.score)"
        return cell
    }

Class Poster lưu dữ liệu đổ vào custom UITableViewCell

import Foundation
import UIKit
class Poster {
    var title: String
    var score: Float
    private var _image: UIImage
    var image: UIImage {
        get {
            return _image
        }
    }
    
    init (title: String, imagePath: String, score: Float) {
        self.title = title
        _image = UIImage(named: imagePath)!
        self.score = score
    }
}

Khóa học lập trình di động tại Techmaster:

Để cài đặt MacOSX lên phần cứng không phải Apple liên hệ chuyên gia cài Hackintosh:

  • Nguyễn Minh Sơn: 01287065634
  • Huỳnh Minh Sơn: 0936225565
  • Website: caidatmacos.com 
  •