2016-03-29 19 views
0

Bu yüzden ViewController'da bir UITableView var ve UITableView değerleri bir dizi kullanılarak dolduruluyor. Bir kullanıcı hücrelerden birine dokunduğunda, başka bir denetleyiciye götürüleceğini varsayar. Peki, uygulama yüklendiğinde ve ilk hücreye hiçbir şey yapılmadığında, ikinci hücre tıklanırsa, ilk hücre ile ilişkili görüntü denetleyici görünür ve ardından oradan yokuş aşağı gider. Soruna bir çözüm bulamıyorum, bu yüzden beni doğru yöne çevirebilecek kişilere sorarım diye düşündüm. İşte ilgili kod. Şimdiden teşekkür ederim!UITableView ile ilgili sorunlar

import UIKit 

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

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

private let choices = ["About this App", "Touch Counting", "Slider Counting", "Calculator", "Date Picker"] 
private let simpleTableID = "simpleTableID" 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return choices.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableID) 

    if cell == nil { 
     cell = UITableViewCell(style: .Default, reuseIdentifier: simpleTableID) 
    } 
    cell?.textLabel?.text = choices[indexPath.row] 
    return cell! 
} 

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 
    switch(indexPath.row) { 
     case 0: 
      let vc = storyboard?.instantiateViewControllerWithIdentifier("AboutThisApp") 
      presentViewController(vc!, animated: true, completion: nil) 
     case 1: 
      let vc = storyboard?.instantiateViewControllerWithIdentifier("TouchCounting") 
      presentViewController(vc!, animated: true, completion: nil) 
     case 2: 
      let vc = storyboard?.instantiateViewControllerWithIdentifier("SlidingCounter") 
      presentViewController(vc!, animated: true, completion: nil) 
     case 3: 
      let vc = storyboard?.instantiateViewControllerWithIdentifier("Calculator") 
      presentViewController(vc!, animated: true, completion: nil) 
     case 4: 
      let vc = storyboard?.instantiateViewControllerWithIdentifier("Date") 
      presentViewController(vc!, animated: true, completion: nil) 
     default: 
      NSLog("NEVER!") 
    } 
} 
} 

cevap

2

Değişimi:

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 

için:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

didSelectRowAtIndexPath kullanıcı bir tablo görünümünde satırı seçer çağrılan, ancak bir sıra seçimi kaldırıldığında zaman didDeselectRowAtIndexPath olur ki, denir İlk satır kullanıcı ikinci sıraya dokunduğunda.

+0

Teşekkür ederiz! Şimdi aptalım ama teşekkür ederim! – user3727648