2015-12-09 55 views
1

我从我的API中获取数据后有一个表视图。但是现在我收到一条错误消息“源文件中的编辑器占位符”。我只是不知道我在哪里做错了。请给点意见?在SWIFT中的表视图中填充自定义单元格时出错

这里是我的代码 -

import UIKit 

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource 
{ 

    @IBOutlet weak var tblvww: UITableView! 
    var dict = [:] 

    override func viewDidLoad() 
    { 
     super.viewDidLoad() 



    func fetchdata() 
    { 
     let url = NSURL(string: "***") 
     let request = NSURLRequest(URL: url!) 
     let urlsession = NSURLSession.sharedSession() 
     let jsonquery = urlsession.dataTaskWithRequest(request) { (data, response, error) -> Void in 

      if let retrieveddata = data 
      { 
       self.dict = (try! NSJSONSerialization.JSONObjectWithData(retrieveddata, options: NSJSONReadingOptions.MutableContainers)) as! NSDictionary 
      } 


     } 
     jsonquery.resume() 

    } 


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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 

     let cell = tableView.dequeueReusableCellWithIdentifier("cellreuse", forIndexPath: indexpath) as! CustomTableViewCell `[![//here I get the error "Editor placeholder in source file"][1]][1]` 

     let vendorname = dict.valueForKey("vendor")?.objectAtIndex(0).valueForKey("name") 
     cell.vndrlbl.text = vendorname as? String 
     return cell 


    } 


} 

如果傻冒使用Xcode 7.x版我还附上我的项目的截屏,以使事情更加清楚

enter image description here

+0

也许这两个链接会帮助你? http://stackoverflow.com/questions/31968278/xcode-7-err-editor-placeholder-in-source-code http://stackoverflow.com/questions/33088305/xcode-7-error-editor-placeholder-in -source-file – Moonwalkr

+0

我已经读过,但这里的东西是不同的。 –

+0

你最初是否从其他地方粘贴过这段代码? – Moonwalkr

回答

0

尝试删除as! CustomTableViewCell downcast。只需使用let cell = tableView.dequeueReusableCellWithIdentifier("cellreuse", forIndexPath: indexpath)就够了。

+0

好吧,我的编译器如何识别“cell”是我的customTableView子类的一种类型? –

0

不使用indexPath所以才删除。

使用此片段:

let cell: TestTableViewCell = tableView.dequeueReusableCell(withIdentifier: "CellMate") as! TestTableViewCell 

清洁并运行该项目,并享受!

相关问题