title: Selecting a TableViewCell provides nil for indexPathForSelectedRow()?.row in Swift
body: <p>I have been trying to integrate a Pinboard bookmarks view (by parsing an RSS Feed and displaying it in a TableView) in my browser app, and I'm encountering a few issues, the main one is that selecting a cell always returns nil and causes a crash.</p>
  
  <p>I followed <a href="http://rshankar.com/blogreader-app-in-swift/" rel="nofollow">this guide</a> to create the view.</p>
  
  <p>Loading the feed in the BlogReader complete project works perfectly, but using it on my own project always returns nil in indexPathForSelectedRow in the prepareForSegue function on the end.</p>
  
  <p>Since my app is a browser, my Storyboard is set differently than the one on the BlogReader one. I have the main ViewController that includes a WKWebView and a UIButton, tapping the button performs a show segue to BookmarksViewController which has a container with an embed segue to BookmarksTableViewController - the TableView. BookmarksTableViewController has a show segue with the identifier "viewbookmark" to the main ViewController.</p>
  
  <p>Here is the code I used:</p>
  
  <pre><code>import UIKit
  class BookmarksTableViewController: UITableViewController, NSXMLParserDelegate {
  
  var parser: NSXMLParser = NSXMLParser()
  var bookmarks: [Bookmark] = []
  var bookmarkTitle: String = String()
  var bookmarkLink: String = String()
  var eName: String = String()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      let url:NSURL = NSURL(string: "http://feeds.pinboard.in/rss/secret:XXX/u:XXXX/")!
      parser = NSXMLParser(contentsOfURL: url)!
      parser.delegate = self
      parser.parse()
  }
  
  // MARK: - NSXMLParserDelegate methods
  
  func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [NSObject : AnyObject]) {
      eName = elementName
      if elementName == "item" {
          bookmarkTitle = String()
          bookmarkLink = String()
      }
  }
  
  func parser(parser: NSXMLParser, foundCharacters string: String?) {
      let data = string!.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
      if (!data.isEmpty) {
          if eName == "title" {
              bookmarkTitle += data
          } else if eName == "link" {
              bookmarkLink += data
          }
      }
  }
  
  func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
      if elementName == "item" {
          let bookmarkItem: Bookmark = Bookmark()
          bookmarkItem.bookmarkTitle = bookmarkTitle
          bookmarkItem.bookmarkLink = bookmarkLink
          bookmarks.append(bookmarkItem)
      }
  }
  
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  // MARK: - Table view data source
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return bookmarks.count
  }
  
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
  
      let bookmarkItem: Bookmark = bookmarks[indexPath.row]
      cell.textLabel?.text = bookmarkItem.bookmarkTitle
  
      return cell
  }
  
  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
      return 50.0
  }
  
  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      tableView.deselectRowAtIndexPath(indexPath, animated: true)
  
      // get to the next screen
      self.performSegueWithIdentifier("viewbookmark", sender: self)
  }
  
  
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)  {
          if segue.identifier == "viewbookmark" {
              let selectedRow = tableView.indexPathForSelectedRow()?.row
              let bookmarkItem: Bookmark = bookmarks[selectedRow!]
              let viewController = segue.destinationViewController as! ViewController
              viewController._bookmarkLink = bookmarkItem.bookmarkLink
              let url: NSURL = NSURL(string: bookmarkItem.bookmarkLink)!
              let request: NSURLRequest = NSURLRequest(URL: url)
              viewController._webView!.loadRequest(request)
          }
      }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks,</p>
  
  <p>PastaCoder</p>