我想实现在IOS的功能,使用户点击UIPickerController即didSelectRow和数据发送到另一个视图控制器CoreData如何将数据发送到另一个视图控制器
我使用的IOS 10,CoreData这里是一瞥我如何做到这一点。
// fetch data from the Core data model
func fetchData(){
// fetch the entity
//1st stage:what is going to fetchgo and fetch ProductDetails
let fetchRequest : NSFetchRequest<ProductDetails>
= ProductDetails.fetchRequest()
// perform the above action :
do {
self.data = try context.fetch(fetchRequest)
for d in data {
coursetitle = d.courseName!
print("course title is: \(coursetitle)")
}
self.PickerCourse.reloadAllComponents()
}
catch {
// handle any errors
let error = error as NSError
print("A Error has occurred while fetching data: \(error) !")
}// end of catch statement
}// end of fetch data method
以上是获取从核心数据的数据
我那么这个通过我的load方法加载到UIPicker
//加载数据到选择器
func loadProductData(){
if let item = productsToEdit {
// can invoke relational ie toProductDetails
if let store = item.toStore{
var index = 0
repeat{
// populate in UIPicker
let sIndex = data[index]
if sIndex.courseName == store.name
{
PickerCourse.selectRow(index,
inComponent: 0, animated: false)
break // out of the loop
}
index += 1 // increment index by 1
}while (index < data.count)
}
}// end of item check
}// end of load product data
我取数据的方法
这里是问题
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int,
inComponent component: Int) {
if component == 0{
// what ever the row is selected assign the value to variable.
CourseSelectedIndex = row
productData = [data[row]]
print("user has selected row at: \(productData)")
//even if I include a segue here I get a error state Array can
// not be assign to NSObject
}
}
我希望以上提供的信息绰绰有余,您对正确方向的支持将非常感谢。
谢谢
您可以使用行传递填充到数组中的数据。 –