2016-01-25 65 views
0

嗨,大家好,我有一個問題。在許多視頻之後,我不明白如何使用Core Data來存儲陣列。快速核心數據陣列

我有一個應用程序,在一個視圖中,我推出了16 TextLabel。我需要使用Core Data來存儲字符串列表。當我啓動程序時,我需要從數組中加載數據。但有時我需要用文本字段中的文本更改一個TextLabel的數據,然後重新加載所有16個文本標籤。

有人可以幫助我的代碼?

對不起,但我還沒有理解它是如何工作的。

我已經創建了具有核心數據的項目。 謝謝所有

+0

我們希望能幫助您解決代碼問題,但請分享您已擁有的代碼,以便我們可以從某處開始。 –

+0

http://stackoverflow.com/questions/4546811/store-nsarray-in-core-data-sample-code – DogCoffee

回答

1

的第一個建議:用tag s的標籤替換所有的網點。這將產生更少的代碼,這將更具可讀性。您可以使用方便的循環來填寫標籤。例如,您的「主要」標籤可能具有標籤10-17,
您的「次要」標籤可能具有標籤20-27。

爲了得到一個特定的標籤,只需要使用

let label = view.viewWithTag(20) as! UILabel 

其次,用於存儲16個字符串數組,使用NSUserDefaults這是更簡單,專爲這種數據量和類型。

NSUserDefaults.standardUserDefaults().setObject(array, forKey: "myArray") 
-1

有我的代碼。在這個視圖中,我想使用數組設置所有16個文本標籤。當我按下其中一個文本標籤下的按鈕時,我需要更改granigliatoreTF中的字符串數據,然後重新加載所有16個文本標籤。我只實現了一個啓動按鈕。感謝所有

進口的UIKit 進口CoreData

類DisposizioneGranigliatori:UIViewController中,UIPickerViewDelegate,UIPickerViewDataSource {

var disposizione = [NSManagedObject]() 

@IBOutlet var granigliatoreTF: UITextField! 
@IBOutlet var principale1LB: UILabel! 
@IBOutlet var principale2LB: UILabel! 
@IBOutlet var principale3LB: UILabel! 
@IBOutlet var principale4LB: UILabel! 
@IBOutlet var principale5LB: UILabel! 
@IBOutlet var principale6LB: UILabel! 
@IBOutlet var principale7LB: UILabel! 
@IBOutlet var principale8LB: UILabel! 

@IBOutlet var secondario1LB: UILabel! 
@IBOutlet var secondario2LB: UILabel! 
@IBOutlet var secondario3LB: UILabel! 
@IBOutlet var secondario4LB: UILabel! 
@IBOutlet var secondario5LB: UILabel! 
@IBOutlet var secondario6LB: UILabel! 
@IBOutlet var secondario7LB: UILabel! 
@IBOutlet var secondario8LB: UILabel! 

@IBOutlet var modifiche: UIView! 

@IBOutlet weak var picker: UIPickerView! 

var pickerData : [[String]] = [[String]]() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    modifiche.hidden = true 


    pickerData = [["12","161","164","165","176","177","245","246","247","250","255","256","262","263","266","267","268","269","270","271","274","275","278","287","289","290","293","301","303","306","307","308","328","330","336","337","340","344","346","347","352","355","357","374","377","381","383","387","391","394","395","399","400","401","403","417","421","423","430","F365","TGF 2666","FTS 2061"],["00","0,09","0,10","0,12","0,12-00","1400","Z","0,14-0,12","0,14","0,16","0,18","0,21","0,25","0,31","0,40","0,52","0,71"]] 

    self.picker.delegate = self 
    self.picker.dataSource = self 

} 

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 pickerData.count 
} 

// The number of rows of data 
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return pickerData[component].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 pickerData[component][row] 
} 

} 


@IBAction func bigbagPrinc1(sender: AnyObject) { 
} 

@IBAction func bigbagSec1(sender: AnyObject) { 
} 

}

+0

你應該在你的問題中包括這個。使用問題下方的「編輯」鏈接。 –