iOS UI测试willDisplayCell工作不正常
我刚开始学习iOS的UI测试。目前,我的应用程序就像facebook(ShowNewFeed)。当用户向下滚动时,如果是最后一行,我需要请求新数据,我会这样做iOS UI测试willDisplayCell工作不正常,ios,xcode-ui-testing,Ios,Xcode Ui Testing,我刚开始学习iOS的UI测试。目前,我的应用程序就像facebook(ShowNewFeed)。当用户向下滚动时,如果是最后一行,我需要请求新数据,我会这样做 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.tblSortingInListi
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tblSortingInListingVC)
{
return;
}
if (tableView == self.tblListing || tableView == self.searchDisplayController.searchResultsTableView)
{
NSInteger lastRow = 0;
if (tableView == self.tblListing) lastRow = self.viewData.count - 1;
else lastRow = self.searchViewData.count - 1;
if ([indexPath row] == lastRow)
{
if(tableView == self.tblListing || tableView == self.searchDisplayController.searchResultsTableView)
{
[self loadMoreToListingView]; //Method to request to server to get more data
}
}
return;
}
}
问题是if([indepath row]==lastRow)始终为true,并且它会继续请求我是否像这样进行UI测试(键入或滚动表)。我该怎么做才能使它不会一次又一次地请求
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];
您需要一个标志(称为isReload
)来再次管理您的请求。
那么你如何管理这个标志呢?。它在ViewController中非常简单
定义一个变量isReload
并设置其初始值YES
。现在检查isReload
标志,以调用loadMoreToListingView
方法中的web服务
-(void)loadMoreToListingView {
if (isReload) {
// here call your web -service ...
}
}
现在,为了响应web服务,您需要检查is搜索列表&更新isReload
标志,正如我下面所做的
NSArray *searchData = response[@"searchData"];
// So when ever no data comes from server then this flag will be flase.
// So isReload will not call webservice Again&again
isReload = gps_details.count > 0;
谢谢但如果我不做UI测试,一切都正常工作。它不会一次又一次地打电话。