我正在尝试创建类Student的新对象,但在调用函数createnewStudent
时出现错误
无法使用类型'的参数列表调用'CreateStudent'(NSManagedObjectContext,combination:String,stream:String,name:String,DOB:NSDate,gender:UISegmentedControl!,DOA:NSDate,fathername:UITextField,mothername:UITextField ,familyincome:Int,emailid:String,phonenumber:Int)'
我该如何处理?
这是我的ViewController.swift文件:
import UIKit
import CoreData
class PortalViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var coursePicker: UIPickerView!
@IBOutlet weak var combination: UILabel!
@IBOutlet weak var streamPrint: UILabel!
@IBOutlet weak var genderSelected: UISegmentedControl!
@IBOutlet weak var DOB: UIDatePicker!
@IBOutlet weak var studentName: UITextField!
@IBOutlet weak var fatherName: UITextField!
@IBOutlet weak var fathersIncome: UITextField!
@IBOutlet weak var mothersName: UITextField!
@IBOutlet weak var mothersIncome: UITextField!
@IBOutlet weak var phoneNumber: UITextField!
@IBOutlet weak var emailID: UITextField!
var newStudent = Student()
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
let stream = ["Science","Arts","Commerce"]
let combinationScience = ["PCM", "PMCs", "CBZ"]
let combinationArts = ["HEP","English","Kannada"]
let combinationCommerce = ["BBM", "Economics","xyz"]
var selectedRow = 0
func pickerView(pickerView : UIPickerView , didSelectRow row : Int , inComponent component : Int){
switch component {
case 0 :
selectedRow = row
streamPrint.text = stream[row]
coursePicker.reloadAllComponents()
case 1 :
switch selectedRow {
case 0: combination.text = combinationScience[row]
case 1: combination.text = combinationArts[row]
case 2: combination.text = combinationCommerce[row]
default : combination.text = "combination"
}
default : selectedRow = 0
}
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 3
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
switch component {
case 0 : return stream[row]
case 1 :
switch selectedRow {
case 0: return combinationScience[row]
case 1: return combinationArts[row]
case 2: return combinationCommerce[row]
default: return nil
}
default: return nil
}
}
@IBAction func proceed(sender: AnyObject) {
var fi1 = fathersIncome.text.toInt()
var fi2 = mothersIncome.text.toInt()
var fi = fi1! + fi2!
var newStudent = Student.CreateStudent(managedObjectContext!, combination: combination.text!, stream: streamPrint.text!, name: studentName.text!, DOB: DOB.date, gender: genderSelected, DOA: DOB.date, fathername: fatherName!, mothername: mothersName!, familyincome: fi, emailid: emailID.text!, phonenumber: phoneNumber.text.toInt()!)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// 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?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
这是我的NSManagedObject文件 进口基金会 导入CoreData
class Student: NSManagedObject {
@NSManaged var combination: String
@NSManaged var currentSemester: NSNumber
@NSManaged var dateOfAdmition: NSDate
@NSManaged var dateOfBirth: NSDate
@NSManaged var emailID: String
@NSManaged var familyIncome: NSNumber
@NSManaged var fatherName: String
@NSManaged var gender: String
@NSManaged var motherName: String
@NSManaged var name: String
@NSManaged var phoneNumber: NSNumber
@NSManaged var registerNumber: NSNumber
@NSManaged var stream: String
class func CreateStudent(moc : NSManagedObjectContext, combination : String, stream : String, name : String , DOB : NSDate, gender : String, DOA : NSDate,fathername :String, mothername: String, familyincome : Int , emailid : String, phonenumber : Int)-> Student{
let newStudent = NSEntityDescription.insertNewObjectForEntityForName("Student", inManagedObjectContext: moc) as! Student
newStudent.combination = combination
newStudent.stream = stream
newStudent.name = name
newStudent.dateOfBirth = DOB
newStudent.dateOfAdmition = DOA
newStudent.fatherName = fathername
newStudent.motherName = mothername
newStudent.familyIncome = familyincome
newStudent.emailID = emailid
newStudent.phoneNumber = phonenumber
return newStudent
}
}
答案 0 :(得分:1)
当您传递UISegmentedControl
值时,您正在为性别参数传递String
个实例。
当您在fatherName
个实例中传递时,请检查motherName
和UITextField
。