if segue.identifier == "postCall" {
let vc: PostCallViewController = segue.destinationViewController as PostCallViewController
let indexPath = tableView.indexPathForSelectedRow()
let cell = fetchedResultsController.objectAtIndexPath(indexPath!) as Contacts
vc.contact = cell
}
这次我想加载来自不同来源的数据的vc.contact
@IBOutlet weak var pic: UIImageView!
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "numberSelected" {
let vc: EditViewController = segue.destinationViewController as EditViewController
vc.contact.status = "newCall"
vc.contact.created = NSDate()
vc.contact.phone = selectedNumber
vc.contact.phoneType = selectedType
vc.contact.name = nameLabel.text!
vc.contact.photo = UIImageJPEGRepresentation(pic.image,1)
vc.contact.memo = ""
}
}
class EditViewController: UIViewController {
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var phoneLabel: UILabel!
@IBOutlet weak var numField: UITextField!
@IBOutlet weak var userPic: UIImageView!
@IBOutlet weak var memoArea: UITextView!
var img:NSData!
var contact: Contacts!
let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
let managedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext
override func viewDidLoad() {
super.viewDidLoad()
nameField.text = contact?.name
phoneLabel.text = contact?.phoneType
numField.text = contact?.phone
memoArea.text = contact?.memo
img = contact?.photo
userPic.image = UIImage(data: img)
}
我继续获得可选的nil错误
vc.contact.phone = selectedNumber
以及该块中的其余行,即使它们都不是可选变量。
这种类型的传递数据是否允许将coredata对象分解为其属性? 我想我可以在不使用核心数据的情况下单独传递变量,但是还有另一个segue导致使用coredata联系实体的同一个控制器,我希望保持一致