Last active
August 21, 2016 12:20
-
-
Save tkc/035e16f0cc194b1014e63f865d1c8c58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TouchCellDelegate { | |
func getNo(id: Int) -> Void | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomeCell: UITableViewCell | |
{ | |
var id:Int? | |
var delegate: TouchCellDelegate? | |
var titleLabel = UILabel(); | |
override init(style: UITableViewCellStyle, reuseIdentifier: String!) | |
{ | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
titleLabel = UILabel(frame: CGRectMake(10, 2, 300, 15)); | |
titleLabel.text = ""; | |
titleLabel.font = UIFont.systemFontOfSize(12) | |
self.addSubview(titleLabel); | |
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(CustomeCell.handleTap(_:))) | |
titleLabel.addGestureRecognizer(gestureRecognizer) | |
self.bringSubviewToFront(titleLabel); | |
titleLabel.userInteractionEnabled = true | |
} | |
func handleTap(gestureRecognizer: UIGestureRecognizer) { | |
self.delegate?.getNo(self.id!) | |
} | |
required init(coder aDecoder: NSCoder) | |
{ | |
super.init(coder: aDecoder)! | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainView: UIViewController, UITableViewDelegate, UITableViewDataSource,TouchCellDelegate { | |
private var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.prepareTable() | |
} | |
func prepareTable(){ | |
tableView = UITableView(frame: CGRect(x: 0, y:0, width: self.view.frame.width, height:self.view.frame.height)) | |
tableView.dataSource = self | |
tableView.delegate = self | |
tableView.registerClass(CustomeCell.self, forCellReuseIdentifier: "cell") | |
self.view.addSubview(tableView) | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 10 | |
} | |
func getNo(id:Int) -> Void { | |
print(id) | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomeCell | |
cell.delegate = self | |
cell.id = indexPath.row | |
cell.titleLabel.text="demo title" | |
return cell | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment