我在选项卡视图控制器中设置问题(标签)的方法中设置了一个 if 语句。该代码从 xml 文件和当前选项卡视图标题中获取数据来设置问题。在第一次调试代码运行时,它给了我“Page 1”==“Page 1”并执行操作,但是当我在选项卡栏上选择另一个视图控制器时,我得到“Page 2”==“Page 2”虽然调试,但它不使用 if 语句执行逻辑。如果我让它 if(1){logic} 它两次都执行逻辑,但不会将我的问题分成第 1 页和第 2 页。视图和视图名称是使用来自同一个 xml 文件的信息动态创建的,所以有没有拼写错误的机会。
这是有问题的代码。任何帮助都会很好,因为经过数小时的尝试思考和在线搜索试图找出为什么真正的 if 语句第二次无法通过代码工作,我感到头疼。
//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];
}