2015-06-13 5 views
1

Я создаю приложение, где у меня есть UITableView, в который пользователь добавляет данные, и я хочу, чтобы пользователь мог использовать эту ячейку и видеть более подробную информацию о ячейке, которую они выбрали. Я установил segue из ячейки в свой cellDetailController, где позже добавлю все детали ячейки, которую они выбрали. Когда я запускаю приложение и пытаюсь нажать на ячейку для перехода, он просто выбирает ячейку, и ничего не происходит. Что я здесь делаю неправильно? Вот моя раскадровка установить:UITableViewCell Segue не работает

(я не могу загружать фотографии еще так вот ссылка) http://tinypic.com/r/2ivcwsj/8

Heres код для моего класса связан с моим Tableview:

import UIKit 

typealias eventTuple = (name: String, date: String) 

var eventList : [eventTuple] = [] 

    class TableViewController: UIViewController, UITableViewDelegate { 

     @IBOutlet weak var eventTable: UITableView! 

     override func viewDidLoad() { 
      super.viewDidLoad() 

     } 

     override func viewDidAppear(animated: Bool) { 
      eventTable.reloadData() 


     } 

     override func didReceiveMemoryWarning() { 
      super.didReceiveMemoryWarning() 
      // Dispose of any resources that can be recreated. 
     } 

     // MARK: - Table view data source 



     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
      // #warning Incomplete method implementation. 
      // Return the number of rows in the section. 
      return eventList.count 
     } 


     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
      let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell") 

      cell.textLabel?.text = eventList[indexPath.row].name 
      cell.detailTextLabel?.text = eventList[indexPath.row].date 

      return cell 
     } 



     /* 
     // Override to support editing the table view. 
     override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
      if editingStyle == .Delete { 
       // Delete the row from the data source 
       tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
      } else if editingStyle == .Insert { 
       // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
      }  
     } 
     */ 

     /* 
     // Override to support rearranging the table view. 
     override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { 

     } 
     */ 

     /* 
     // Override to support conditional rearranging of the table view. 
     override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
      // Return NO if you do not want the item to be re-orderable. 
      return true 
     } 
     */ 


     // MARK: - Navigation 

     // In a storyboard-based application, you will often want to do a little preparation before navigation 
     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
      if(segue.identifier == "showDetailSegue") { 

      }  
     } 
    } 

ответ

8

Перетащите переход из tableViewController (желтый значок в верхней части viewController), а не из tableCell. Затем дайте этому сегменту идентификатор.

Override didSelectRowAtIndexPath и выполнить SEGUE здесь через performSegueWithIdentifier()

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    // pass any object as parameter, i.e. the tapped row 
    performSegueWithIdentifier("showDetailSegue", sender: indexPath.row) 
} 
+3

"не из TableCell", но почему? Я вижу, что он тоже работает. –

+0

Подсоединение к ячейке с помощью селекции - это правильный способ сделать это. Зависит от того, чего вы хотите. Если вы подключаете его непосредственно к соте, вы также не должны вызывать 'performSegue' в' didSelectRowAtIndexPath'. – shim

Смежные вопросы