Reputation: 6133
I just started studying for UI Testing in iOS. Currently, my app is just like facebook (show newfeed). When user scroll down and if it is last row, I need to request new data and I do like this.
-(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;
}
}
Problem is that if ([indexPath row] == lastRow) is always true and it keep on requesting if I do UI testing like this (either typing or scrolling tables). How shall I do so that it won't request again and again?
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];
Upvotes: 1
Views: 265
Reputation: 374
Looks like problem described here:
https://medium.com/@t.camin/apples-ui-test-gotchas-uitableviewcontrollers-52a00ac2a8d8
In short:
the tableView(_:willDisplay:forRowAt:) is being called repeatedly while running UI Tests, even for offscreen cells
Upvotes: 0
Reputation: 1852
you need a flag (called isReload
) to manage your request again & again.
So How do you manage this flag ?. It's very simple in your ViewController
define a variable isReload
and set initial value of it YES
. now check isReload
flag to call web service in loadMoreToListingView
method that you implemented like.
-(void)loadMoreToListingView {
if (isReload) {
// here call your web -service ...
}
}
Now In Response of web-service, you need to check is search list & update isReload
flag as I'm doing below.
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;
Upvotes: 0