Swift ViewController没有成员名 [英] Swift ViewController does not have member named

查看:148
本文介绍了Swift ViewController没有成员名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经通过所有的线程,应该处理这个问题,没有人似乎纠正我的问题。

OK, I've been through all of the threads that supposedly deal with this problem and none of them seem to rectify my issue.

基本上我有一个tableview设置核心数据,当我进入下一个视图控制器,我想传递一些数据。因为你知道传递的数据必须已经在目标视图控制器中声明。但是我不断收到一个错误,说ViewController没有一个成员名称nItem(我传递的变量)。

Basically I have a tableview setup with core data and when I segue into the next view controller I want to pass some data. As you know the data being passed must already be declared in the destination view controller, which it is. But I keep getting an error saying the ViewController does not have a member name nItem (the variable I am passing).

这里是代码段,数据从表视图控制器:

Here is the section of code that deals with passing the data from the table view controller:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.

    if segue.identifier == "editCurrentMed" {
        let cell = sender as UITableViewCell
        let indexPath = tableView.indexPathForCell(cell)
        let addEditMedVC : ViewController = segue.destinationViewController as ViewController
        let nItem : Meds = frc.objectAtIndexPath(indexPath!) as Meds
        addEditMedVC.nItem = nItem
    }

}

这里是我的视图控制器的顶部,它声明变量以及视图有负载部分,因为访问

And here is the top section of my view controller that is declaring the variable along with the view did load section because that accesses it for when the data is edited.

import UIKit
import CoreData

class addEditMedVC: UIViewController {

    var nItem : Meds? = nil

    @IBOutlet weak var medName: UITextField!
    @IBOutlet weak var dosage: UITextField!
    @IBOutlet weak var timeToTake: UISegmentedControl!

    override func viewDidLoad() {
        super.viewDidLoad()

        if nItem != nil {
        medName.text = nItem!.name
        dosage.text = nItem!.dose
        nItem!.time = "Morning"
        }

        // Do any additional setup after loading the view.
}

任何帮助都非常感谢。提前感谢。

Any help is greatly appreciated. Thanks in advance.

推荐答案

为可选属性分配非可选值应能正常工作。但你似乎混淆了你的类名。

Assigning a non-optional value to an optional property should work as expected. But you seem to have confused your class names.

从你的 prepareForSegue 视图控制器 ViewController 。然而,在你的类文件中,你写的是 UIViewController 的子类,名为 addEditMedVC 名称而不是通常大写的类名称)。

From your prepareForSegue it is evident that the class of the destination view controller is ViewController. In your class file, however, you write it is a subclass of UIViewController called addEditMedVC (which looks more like a variable name rather than the usually capitalized class name).

- >将类重命名为 ViewController

-> Rename your class to ViewController.

这篇关于Swift ViewController没有成员名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆