2016-08-19 77 views
0

我想在我的swift代碼中使用一個選擇器視圖,我幸運地運行。但是每次我加載程序時,我的選擇器視圖都會創建一個自己的鬼影。爲什麼會發生?我是否需要對我的代碼進行任何調整? hereUIPickerView鬼圖像

import Foundation 
import UIKit 

class ViewTwo: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { 

    @IBOutlet weak var pickerMenSplit: UIPickerView! 

    //var menPickerSplit: [String] = [String]() 
    var menPickerSplit = ["A", "B", "C", "D", "E"] 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     //Connect Data: 
     pickerMenSplit.delegate = self 
     pickerMenSplit.dataSource = self 

     //Input data into the Array: 


    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
    //the number of columns of data 
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 
     return 1 
    } 

    //the number of rows of data 
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
     return menPickerSplit.count 
    } 

    //the data to return for the row and component (column) that's being passed in 
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
     return menPickerSplit[row] 
    } 

} 

回答

0

您是否嘗試過清理你的項目? cmd + shift + k,如果這不起作用,請嘗試從模擬器中刪除您的應用程序,然後嘗試再次運行它。

+0

我做了清理,它沒有幫助。我曾嘗試在全新文件上運行該應用程序,並注意到在原始ViewController導航窗格上它可以正常工作,但是如果使用新類創建第二個導航窗格,即文件開始以不同方式運行時。我不確定這些問題可能是什麼,但我想弄清楚爲什麼在第二個和第三個視圖控制器上構建它會在拾取器上創建這些幻影圖像。 – Phantomgrahf

+0

有沒有人有一個想法,我可以解決這個問題? – Phantomgrahf