Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如果在xcode中以编程方式创建标签时Station不起作用_Objective C_Xcode_If Statement_Uilabel - Fatal编程技术网

Objective c 如果在xcode中以编程方式创建标签时Station不起作用

Objective c 如果在xcode中以编程方式创建标签时Station不起作用,objective-c,xcode,if-statement,uilabel,Objective C,Xcode,If Statement,Uilabel,我在一个方法中设置了一个if语句,以在选项卡视图控制器中设置问题标签。代码从xml文件和当前选项卡视图标题中获取数据以设置问题。当调试代码第一次运行时,它给我第1页==第1页并执行操作,但当我在选项卡栏上选择另一个视图控制器时,我在调试时得到第2页==第2页,但它不执行if语句的逻辑。如果我把它设为if1{logic},它会同时执行逻辑,但不会将我的问题分为第1页和第2页。视图和视图名称是使用来自同一xml文件的信息动态创建的,因此没有拼写错误的机会 这是有问题的代码。任何帮助都会很好,因为我在

我在一个方法中设置了一个if语句,以在选项卡视图控制器中设置问题标签。代码从xml文件和当前选项卡视图标题中获取数据以设置问题。当调试代码第一次运行时,它给我第1页==第1页并执行操作,但当我在选项卡栏上选择另一个视图控制器时,我在调试时得到第2页==第2页,但它不执行if语句的逻辑。如果我把它设为if1{logic},它会同时执行逻辑,但不会将我的问题分为第1页和第2页。视图和视图名称是使用来自同一xml文件的信息动态创建的,因此没有拼写错误的机会

这是有问题的代码。任何帮助都会很好,因为我在数小时的尝试思考和在线搜索后感到头痛,试图找出为什么true 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];


}

您不应该使用pageTital==questionPage来比较两个字符串,您应该使用[pageTital IsequalString questionPage]

+1来解释:使用==进行比较意味着测试它们是否是相同的对象。使用-isEqualToString进行比较:意味着测试对象是否具有相同的值。后者对于两个不同的对象仍然是正确的,而前者不能。谢谢。我想过去15年来,微软C++的老代码是嵌入在我大脑中的。