2016-04-12 7 views
0

iOSでUIテストを勉強し始めました。現在、私のアプリはfacebook(newfeedを表示)のようなものです。ユーザーが下にスクロールし、最後の行である場合、私は新しいデータを要求する必要があり、私はこれを好きです。iOS UIテストwillDisplayCellが正しく動作しない

-(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; 
    } 
} 

問題は場合([indexPath行] == LASTROW)は常に真であると私はこのようなUIテスト(タイピングまたはスクロールテーブルのいずれか)を行う場合、それは要求し続けるということです。何度も何度も要求しないように私はどうしたらよいですか?

XCUIApplication *app = [[XCUIApplication alloc] init]; 
[app.tables.staticTexts[@"Apr 04 16:28"] tap]; 

答えて

0

あなたは再び再び&あなたの要求を管理するためのフラグ(isReloadと呼ばれる)が必要です。 このフラグをどうやって管理しますか? ViewControllerで非常に簡単です 変数isReloadを定義し、その初期値をYESに設定します。あなたのように実装したloadMoreToListingViewメソッドでWebサービスを呼び出すためにisReloadフラグをチェックしてください。私は以下のやっているよう

-(void)loadMoreToListingView { 

    if (isReload) { 
     // here call your web -service ... 
    } 
} 

今のWebサービスの応答では、あなたがチェックする必要が検索リスト&更新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; 
+0

ありがとう。しかし、私がUIテストをしなければ、すべてが適切に動作しています。それは何度も何度も呼び出されません。 –

関連する問題