Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 代码中的问题,需要帮助_Ios_Swift - Fatal编程技术网

Ios 代码中的问题,需要帮助

Ios 代码中的问题,需要帮助,ios,swift,Ios,Swift,我正在尝试用parse构建一个消息应用程序,我刚刚开始编写一些代码。但是它在Xcode 6.4中工作时存在一些问题。有人能帮忙吗。我在课堂上也有问题。我是初学者 @IBOutlet weak var messageTableView: UITableView! var messageArray: [String] = [String]() override func viewDidLoad() { super.viewDidLoad() // Do any additiona

我正在尝试用parse构建一个消息应用程序,我刚刚开始编写一些代码。但是它在Xcode 6.4中工作时存在一些问题。有人能帮忙吗。我在课堂上也有问题。我是初学者

@IBOutlet weak var messageTableView: UITableView!

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

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let testObject = PFObject(className: "TestObject")
    testObject["foo"] = "bar"
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        println("Object has been saved.")
    }
    self.messageTableView.delegate = self
    self.messageTableView.dataSource = self

    messageArray.append("Test 1")
    messageArray.append("test 2")
    messageArray.append("test 3")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell = self.messageTableView.dequeueReusableCellWithIdentifier("MessageCell") as! UITableViewCell

    cell.textLabel?.text = self.messageArray[indexPath.row]

    return cell
}

func tableview(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    return messageArray.count
}
}

我认为您希望在tableView中显示messageArray,但您的委托方法不符合UITableViewDataSource协议,因此请使用以下方法替换您的方法:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.messageTableView.dequeueReusableCellWithIdentifier("MessageCell") as! UITableViewCell

    cell.textLabel?.text = self.messageArray[indexPath.row]

    return cell
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return messageArray.count
}
您的完整代码为:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var messageTableView: UITableView!

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

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.messageTableView.delegate = self
        self.messageTableView.dataSource = self

        messageArray.append("Test 1")
        messageArray.append("test 2")
        messageArray.append("test 3")
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.messageTableView.dequeueReusableCellWithIdentifier("MessageCell") as! UITableViewCell

        cell.textLabel?.text = self.messageArray[indexPath.row]

        return cell
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return messageArray.count
    }

}

这是您的示例项目。

请描述问题。嘿,杰克!技巧101对于一个新程序员和一个新的堆栈用户来说:很好地解释你的问题。先做一些橡皮鸭调试,带着一个我需要在Y班做X的具体例子来这里。。。。我找到了做Z的方法,但我不能让它正确地迷惑人。。。差不多吧。通常只要简单地解释一下你的问题,你就会知道如何解决它。在堆栈上,若你们不这样做,你们的问题无论如何都会很难被接受