2015-02-02 3 views
0

내 앱의 기본 화면으로 표를 만들려고하는데 문제가 있습니다. main.storyboard를 올바르게 설정했지만, "superclass를 오버라이드하지"않는 override func가 있습니다. 오류는 nuberOfRowsInSection 재정의 기능 행에 있습니다. 내 코드는 다음과 같습니다.신속한 테이블 뷰 컨트롤러 설정?

import UIKit 

class ViewController: UITableViewController { 

    var candies = [Candy]() 

    @IBOutlet weak var editButton: UIButton! 

     override func viewDidLoad() { 
      super.viewDidLoad() 

      // Do any additional setup 
      // after loading the view. 

      self.candies = [Candy(name: "Jolly Rancher"),Candy(name: "Snickers"),Candy(name: "Twix"),Candy(name: "Butterfinger"),Candy(name: "Milky Way")] 
     } 
    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    override func tableView(tableView: UITableView, nuberOfRowsInSection section: Int) -> Int { 
    return self.candies.count 
    } 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell 

     var candy : Candy 

     candy = candies [indexPath.row] 

     cell.textLabel?.text = candy.name 
    } 


    @IBAction func editButtonPressed(sender: UIButton) { 
     editButton.setTitle("Save", forState: UIControlState.Normal) 
    } 

} 
+0

맞춤법 오류가 발생했습니다. 그러나 cell.textLabel? .text = candy.name 뒤에 오류가있는 경우 닫기 오류가 수정되었습니다. –

+0

오류가 무엇입니까? – Christian

+0

반환 할 함수에서 반환 값이 누락되었습니다. UITableViewCell –

답변

0

입력 오류가 있습니다. 메소드 nuberOfRowsInSection을 호출합니다. 'n'이 누락되었습니다. 이 메서드는 numberOfRowsInSection이라고합니다.

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

또한 cellForRowAtIndexPath 메서드에서 오류가 발생했습니다. 당신은 셀을 반환해야 :

return cell 
+0

죄송합니다. 하지만 그럴 때 오류가 cell.textLabel 뒤에 오는 닫는 중괄호로 이동합니까? .text = candy.name –

0

그냥 추측 : 내가 아는 한

// this should read "numberOfRowsInSection": ~~v 
override func tableView(tableView: UITableView, nuberOfRowsInSection section: Int) -> Int { 
    return self.candies.count 
} 

, UITableViewController이 매개 변수 nuberOfRowsInSection와 방법을 가지고 있지 않지만,이 매개 변수를 사용하여 하나가 않습니다 numberOfRowsInSection.

작동하지 않는 것을 처리 할 때 코드에서 맞춤법 오류를 확인하십시오.

관련 문제