Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Trying to link a tap event on a table view cell to a controller method

Tags:

xcode

ios

swift

I am new to swift and havne't programmed in objective C. So i'm new :-) trying to do something fairly simple. Link a table view cell click to call a method in the controller like so http://prntscr.com/4m9kf7

Edit:

i have these methods in my MasterController

  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
  override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
 override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

I have added breakpoints in all 4 of them. and when clicking on the cell it doesn't stop in either of them. See Screen shot:

http://prntscr.com/4m9ql0

like image 211
WebQube Avatar asked Sep 12 '14 23:09

WebQube


1 Answers

You need to implement the didSelectRowAtIndexPath delegate method and put your handling code inside it.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
     //CODE TO BE RUN ON CELL TOUCH
}
like image 144
Woodstock Avatar answered Oct 05 '22 23:10

Woodstock