2016-07-05 7 views
0

I 현재 가지고 그 INIT 함수 지정 데이터 소스를 설정하는있는 UITableViewController :있는 UITableViewController

class BookmarkTableViewController: UITableViewController { 
    var date: Date 

    // MARK: - Init 
    init(date: Date, fetchAtLoad: Bool) { 
    self.date = date 
    super.init(style: .plain) 
    self.tableView.dataSource = BookmarkDataSource(date: date) 
    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 
    } 

// ... 
} 

맞춤 데이터 소스는 다음과 같다 :

class BookmarkDataSource: NSObject { 
    let date: Date 

    init(date: Date) { 
    self.date = date 
    super.init() 
    } 
} 

// MARK: - UITableViewDataSource 
extension BookmarkDataSource: UITableViewDataSource { 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 3 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = UITableViewCell() 
    cell.textLabel?.text = "Test content" 

    return cell 
    } 
} 

그러나 시뮬레이터 또는 장치에서 실행할 때 테이블보기에 아무 것도 나타나지 않습니다. 아무도 내가 빠진 것을 아는가?

참고 : 나는 당신의 세포가 제대로 인스턴스화되지 않는 생각 엑스 코드 8.0 베타와 스위프트 3.

답변

5

let cell = UITableViewCell() 

교체. tableView의 dataSource는 게시 한 코드와 함께 nil이됩니다.

class BookmarkTableViewController: UITableViewController { 
    var date: Date 
    var dataSource:BookmarkDataSource 

    // MARK: - Init 
    init(date: Date, fetchAtLoad: Bool) { 
     self.date = date 
     super.init(style: .plain) 
     dataSource = BookmarkDataSource(date: date) 
     self.tableView.dataSource = dataSource 
     self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 
    } 

    // ... 
} 
+0

예! 이거 야. 감사! – Aliou

+1

나는 dataSource 변수 생성에 실패했지만 아이디어를 얻었습니다! – bradkratky

0

을 사용하고 있습니다.

보십시오 당신은 당신의 BookmarkDataSource 개체에 대한 강한 참조를 저장해야

let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
관련 문제