2014-10-07 3 views
4

테이블 뷰 컨트롤러를 만들었지 만 해당 대리자 메서드가 호출되지 않습니다. 나는 몇몇 웹 사이트를 언급했고 내 코드에서 실수를 범하지 않았다. 도와주세요.Swift tableView 대리자 메서드가 호출되지 않습니다.

class FriutsTableViewController: UITableViewController { 
var fruitsList : [AnyObject] = ["We", "love", "swift"]; 

override func viewDidLoad() { 
    super.viewDidLoad() 

    let myCatalog = Catalog() 
    fruitsList = myCatalog.fruits; 
    //let view = ViewController() 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int { 
    return 0 
} 

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

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { 
    var cell = tableView.dequeueReusableCellWithIdentifier("fruitIdentifier") as? UITableViewCell 

    if !cell { 
     cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "fruitIdentifier") 
    } 

    cell!.textLabel.text = fruitsList[indexPath.row] as AnyObject! as String! 
    return cell 
} 

@objc func fetchFruits() { 

} 

미리 감사드립니다.

+4

시도에

return 1 

에 시도 – derdida

+2

스토리 보드 또는 다른 위치에 테이블 위임자를 설정 하시겠습니까? 코드? 당신은해야합니다. – djromero

+0

@derdida : 네가 0이 아닌 값으로 잘 돌아갑니다. 내 잘못은 단순한 실수 야. 정말 고맙습니다. 하나 더하기. – selva

답변

7

는 numberOfSectionsInTableView 1을 반환

numberOfSectionsInTableView. 
+1

왜 신의 뜻으로 사과가 기본값을 0으로 설정 했습니까?!? 하지만 그 해답을 가져 주셔서 감사합니다. –

2

간단히 마스터 - 디테일 애플리케이션 프로젝트를 만들고 tableviewcontroller 코드를 살펴 보시기 바랍니다.

코드를 Xcode에 붙여 넣은 후 몇 가지 작은 문제가 있습니다.

import UIKit //1. remember to import UIKit for UITableViewController 

//2. Do not return a UITableView! Instead, return a UITableView (without !) 
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 0 // you should probably return 1 
    } 

//3.Same as above. remove ! from UITableView, NSIndexPath and UITableViewCell 
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell 

     let object = objects[indexPath.row] as NSDate 
     cell.textLabel?.text = object.description 
     return cell 
    } 

그리고 마지막으로는, 당신이} 끝나는 누락 "클래스 FriutsTableViewController :있는 UITableViewController를 {"

관련 문제