2016-08-03 69 views
1

我的視頻播放器選擇並播放給定的單元格。 我的目標是等到播放另一個視頻才能繼續使用代碼。當放置一個斷點和在調試器手動檢查,然後細胞,但 - :While loop condition not reevaluating

while app.tables.elementBoundByIndex(0).cells.elementBoundByIndex(0).selected {} 

不知何故,在while循環中,重新估計不會發生(>真cell.selected當不再被選擇的單元)。選中 - >假

回答

1

while循環中的視圖層次結構運行檢查不會導致在每個循環之間更新視圖層次結構。該檢查將針對視圖層次結構的緩存版本進行,除非您與應用程序交互,否則將不會更新。

爲確保每次檢查更新視圖層次結構,應使用expectationForPredicate:evaluatedWithObject:handler:waitForExpectationsWithTimeout:handler:

class MyTestCase: XCTestCase { 
    let cell = app.tables.elementBoundByIndex(0).cells.elementBoundByIndex(0) 
    let notSelectedPredicate = NSPredicate(format: "selected == false") 
    expectationForPredicate(notSelectedPredicate, evaluatedWithObject: cell, handler: nil) 
    waitForExpectationsWithTimeout(10, handler: nil) 
    // proceed with the test... 
} 

這種方式,視圖層次對證將刷新每個檢查。

+0

非常感謝youuuu !!!有效!! – romdj