2015-09-09 3 views
0

Я пытаюсь создать приложение для сообщений с 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 
} 
} 
+2

Опишите проблемы. –

+1

Эй, Джек! Подсказка 101 как для нового программиста, так и для нового пользователя Stack: объясните свою проблему WELL. Сначала сделайте «отладку резиновой утки», придите сюда с конкретным «Мне нужно сделать X в классе Y .... Я нашел, как делать Z, но я не могу заставить газнецку правильно бамбука» ... что-то как это. Часто просто объясняя свою проблему, вы получаете представление о том, как ее решить. И на Stack, если вы этого не сделаете, ваш вопрос будет плохо принят в любом случае – Patrice

ответ

0

Я думаю, что вы хотите отобразить messageArray в tableView, но ваши делегаты методы, не соответствующие 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 
    } 

} 

И HERE - ваш образец проекта.

Смежные вопросы