I have setup an if statement in a method to setup questions (labels) in a tab view controller. The code is taking data from a xml file and the current tab view title to setup the questions. While debugging the fist time the code is run it gives me “Page 1” == “Page 1” and preforms the operations, but when I select another view controller on the tab bar I get “Page 2” == “Page 2” while debugging, but it does not do the logic with the if statement. If I make it if(1){logic} it does the logic both times, but does not separate my questions into page 1 and page 2. The view and view names are created dynamically using the information from the same xml file, so there is no chance of misspelling.
Here is the code in question. Any help would be nice as I have a headache after hours of trying thinks and searching online trying to figure out why a true if statement is not working the second time through the code.
//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];
}
You shouldn’t use pageTital == questionPage to compare 2 strings, you should use [pageTital isEqualToString questionPage]