iPhone/Swift 2.0

Custom table cell 커스텀 테이블뷰

코딩저장소 2016. 3. 21. 15:03

import UIKit

import Alamofire


class ChannelViewController: UIViewControllerUITableViewDataSource, UITableViewDelegate{

    

    @IBOutlet var tableView: UITableView!

    

    var channels:[ChannelField]!

    

    override func viewDidLoad() {

        super.viewDidLoad()


        Alamofire.request(.GET, Const.CHANNEL)

            .responseObject { (response: Response<ChannelVo, NSError>) in

                self.channels = (response.result.value?.result)!;

                self.tableView.delegate = self

                self.tableView.dataSource = self

        }

    }

    

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 1

    }

    

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return channels.count

    }

    

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let row:ChannelField = channels[indexPath.row]

        

        if let cell = self.tableView.dequeueReusableCellWithIdentifier("ChannelViewCell", forIndexPath: indexPath) as? ChannelViewCell {

            cell.configureCell(row.userThumbnailUrl, titleLabel: row.title, descriptionLabel:row.userName, videoCountLabel:row.mediaCount)

            return cell

        } else {

            return ChannelViewCell()

        }

    }

    

    func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

        return UITableViewAutomaticDimension

    }

    

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let channel:ChannelField = channels[indexPath.row]

        

        print("MediaID #\(channel.title)!")

        

//        if let rvc = self.storyboard?.instantiateViewControllerWithIdentifier("KYDrawerController") as? KYDrawerController {

//            NSUserDefaults.standardUserDefaults().setValue(section.mediaId, forKey: Const.KEY_MEDIA_ID)

//            NSUserDefaults.standardUserDefaults().synchronize()

//            self.presentViewController(rvc, animated: true, completion: nil)

//        }

        

    }


}










import UIKit

import ImageLoader


class ChannelViewCell: UITableViewCell {


    @IBOutlet var profileImage: UIImageView!

    @IBOutlet var titleLabel: UILabel!

    @IBOutlet var descriptionLabel: UILabel!

    @IBOutlet var videoCountLabel: 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

    }

    

    // init

    func configureCell(profileImage:String, titleLabel:String, descriptionLabel:String, videoCountLabel:String) {

        self.profileImage.load(profileImage)

        self.titleLabel.text = titleLabel

        self.descriptionLabel.text = descriptionLabel

        self.videoCountLabel.text = videoCountLabel

    }

}