2015-12-09 48 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 

清潔並運行該項目,並享受!

相關問題