0
我不知道如何實現我的模擬UITableView
對象正確回答indexPathsForSelectedRows
。 在我的應用程序中,用戶可以(在編輯狀態下)選擇表格視圖中的單元格,它表示給定目錄的文件/文件夾。 一旦用戶選擇一個文件夾項目,應該取消選擇以前選擇的文件項目。我的測試(使用OCHamcrest/OCMockito)看起來像這樣。處理UITableView的indexPathsForSelectedRows
- (void)test_tableViewwillSelectRowAtIndexPath_DeselectsPreviouslySelectedCells
{
// given
[given(self.mockTableView.editing) willReturnBool:YES];
// when
[self.sut tableView:self.mockTableView willSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:SectionIdFile]];
[self.sut tableView:self.mockTableView willSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:SectionIdFolder]];
// then
}
問題是,我可以驗證文件項被選中,但我不能問mockTableView選定的行。有人可以告訴我如何處理?我是否必須自己記錄tableView:selectRowAtIndexPath:animated:scrollPosition:
調用,並在tableView被要求提供這些信息時提供正確的答案?
爲什麼你不能要求選定的行?你已經嘗試過'indexPathsForSelectedRows'方法,它返回nil? – geo
詢問selectedRows的mockTableView總是返回nil,但它應該返回第一次調用willSelectRowAtIndexPath時提供的indexPath的數組。 –