2013-05-14 72 views
1

我正在嘗試編寫使用tableView的單元測試,並且無法訪問單元格。cellForRowAtIndexPath在單元測試中爲零

這始終是零:

- (void)testDidEndEditingUpdatesLiftRecords { 
    TextViewCell *cell = (TextViewCell *) [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 

儘管我設置的數據源中的設置

- (void)setUp { 
    [super setUp]; 
    source = [[MyDataSource alloc] init]; 
    tableView = [[UITableView alloc] init]; 
    [tableView setDataSource:source]; 

什麼能

+1

是否設置爲代表你的表視圖訪問直的? – Amit 2013-05-14 12:58:09

+0

你可以顯示你爲代表寫的代碼嗎? – 2013-05-14 12:59:34

+0

你的tableView中有沒有內容,或者它是空白的? – 2013-05-14 13:10:19

回答

0

實例化一個實際的UITableViewController,這工作正常。

2

張貼here(SWIFT 3)我只好打電話給cellForRow數據源cellForRowAt函數,而不是從tableView.cellForRow功能

//this 
let cell = controller.tableView(controller.tableView, cellForRowAt: IndexPath(row: 0, section: 0)) 

//instead of this 
let cell = controller.tableView.cellForRow(at: IndexPath(row: 0, section: 0))