タブ ビュー コントローラーで質問 (ラベル) を設定するメソッドに if ステートメントを設定しました。コードは、xml ファイルと現在のタブ ビューのタイトルからデータを取得して、質問を設定します。コードが実行される最初の時間をデバッグしているときに、「ページ1」==「ページ1」が表示され、操作が実行されますが、タブバーで別のビューコントローラーを選択すると、「ページ2」==「ページ2」が表示されますデバッグ中ですが、ifステートメントでロジックを実行しません。if(1){logic} にすると、ロジックは両方とも実行されますが、質問がページ 1 とページ 2 に分けられません。ビューとビューの名前は、同じ xml ファイルの情報を使用して動的に作成されるため、スペルミスの可能性はありません。
これが問題のコードです。何時間も思考を試み、オンラインで検索して、真のifステートメントがコードで2回目に機能しない理由を理解しようとした後、頭痛がするので、どんな助けでもいいでしょう。
//setup questions at runtime --not working--
-(void)setupQuestions{
int lableY = 85;
NSString *pageTital = self.pageTabViewLable.title;
NSString *questionPage;
for (int i = 0; i < self.question_array.count; i++) {
self.currentQuestion = [self.question_array objectAtIndex:i]; //Get information of current Question from array
questionPage = self.currentQuestion.Page;
if (pageTital == questionPage){
//Create a Dynamic Label for Question.
UILabel *lablel;
CGRect lableFrame = {155,lableY,600,25};
lablel = [[UILabel alloc] initWithFrame:lableFrame];
lablel.text = self.currentQuestion.Question;
[self.view addSubview:lablel];
lableY += 90; //lable spacing
}
}
}
//at runtime setup tabs --working--
-(void)setupTabPages{
NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; //Create a array to hold tab veiws
if( newArray.count != self.totalTabPageCount) //check to see is amount of veiws and cussrent reated views are the same
{
self.pageTabViewLable.title = [xmlParser1 getPageWithIndexLocation:0]; //set text of inital view
UIStoryboard *storyboard = self.storyboard; //get storyboard context information from view name
if (self.totalTabPageCount != -1) { //check for xml error
for (int i = 1; i < self.totalTabPageCount; i++) { //create additional views from storyboard view
Check_StratusViewController *cvc = [storyboard instantiateViewControllerWithIdentifier:@"Check_StratusViewController1"];
cvc.pageTabViewLable.title = [xmlParser1 getPageWithIndexLocation:i];
[newArray addObject:cvc];
}
[self.tabBarController setViewControllers:newArray animated:YES]; //add the views
}
}
self.totalQuestionCount = [xmlParser1 getTotalQuestionCount];
self.currentQuestion = [[Question alloc] init];
self.question_array = [[NSMutableArray alloc] init];
for (int i = 0; i < self.totalQuestionCount; i++) {
[self.question_array addObject:[xmlParser1 getQuestionAtIndelLocation:i]];
}
[self setupQuestions];
}