2

I programmatically created a UITableView for a custom keyboard extension within the default KeyboardViewController.swift but for some reason the didSelectRowAtIndexPath is not responding at all. I've made sure to set the userInteractionEnabled to true for both the table the cells and made sure to set allowsSelectionDuringEditing to true. The tableView is definitely being populated and the cells get highlighted when I touch them but the logs are not appearing at all (nor is the method breaking when there is a breakpoint on it).

Anyone have any ideas on what I may have screwed up to make this happen?

class KeyboardViewController: UIInputViewController, UITableViewDelegate, UITableViewData Source {

 var tableView: UITableView = UITableView()
 //other setup

override func viewDidLoad() {
  super.viewdidLoad

  // other setup here

  tableView.frame = CGRectMake(0, 0, 320, 160)
  tableView.delegate = self
  tableView.dataSource = self
  tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
  tableView.allowsSelection = true
  tableView.allowsSelectionDuringEditing = true
  tableView.userInteractionEnabled = true
  self.view.addSubview(tableView)
 }

//delegate&datasource methods
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    let sectionTitle = artistSectionTitles[section]
    let sectionArtist = artists[sectionTitle]

    return sectionArtist!.count
}

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

    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
    cell.userInteractionEnabled = true
    let sectionTitle = artistSectionTitles[indexPath.section]
    let sectionArtists = artists[sectionTitle]
    let artist = sectionArtists?[indexPath.row] as NSString

    cell.textLabel?.text = artist
    return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 22
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: false)
    println("You selected cell #\(indexPath.row)!")
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return artistSectionTitles[section]
}

func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! {
    return artistSectionTitles
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return artistSectionTitles.count
}
Brian
  • 14,610
  • 7
  • 35
  • 43
bteng22
  • 61
  • 5

3 Answers3

0

How are you tracking that selection does in fact not work? Because if the rows light up - it should work.

Maybe you are changing the tableView delegate somewhere?

Also try changing the cell selectionStyle property.

Dvole
  • 5,725
  • 10
  • 54
  • 87
  • I set a breakpoint inside didSelectRowAtIndexPath and also have a println statement that's not being logged :\ – bteng22 Mar 31 '15 at 16:30
0

Apparently debugging with new iOS App Extension Types can be pretty sketchy. To hit the debug breakpoint in the didSelectRowAtIndexPath I followed Alex Guerrero's answer from this stackoverflow post. Hopefully it'll help others working with the new app extensions !

https://stackoverflow.com/a/27352955/3282316

Copy and pasted below just in case the post gets removed

Apple has reported this problem as a know issue in Xcode 6.1 release notes:

Localization and Keyboard settings, including 3rd party keyboards, are not correctly honored by Safari, Maps, and developer apps in the iOS 8.1 Simulator. [NSLocale currentLocale] returns en_US and only the English and Emoji keyboards are available. (18418630, 18512161) I'm using Xcode 6.1.1 and seems that it still hasn't been solved but I've discovered a workaround. You should follow this steps:

Open Xcode and in its menu bar click into Xcode > Open Developer Tool > iOS Simulator

Now into iOS Simulator menu bar go to Hardware > keyboard and check if "Connect Hardware Keyboard" is enable. If it is, click it to disable and quit iOS Simulator

Then go back to Xcode and make sure that keyboard is selected as scheme

Click into run button or press Product > Run to build and run you application and in the "Choose an app to run" menu choose Today

When iOS Simulator starts, go to Settings > General > Keyboard > Keyboards > Add New Keyboard and select your own and then press in your keyboard command + shift + H to back to the homescreen

From here I went back into my app and clicked on a cell and the didSelectRowAtIndexPath was responsive!

If the keyboard still doesn't appear: remove the file com.apple.iphonesimulator.plist from ~/Libray/Preferences/ In iOS Simulator menu bar click into iOS Simulator > Reset Content and Settings...

Community
  • 1
  • 1
bteng22
  • 61
  • 5
0

you might have given "no selection" to the TableView's selection property. Please change that and try.

Doble N J
  • 1
  • 1