Search code examples
objective-cxcodenstimer

how to overwrite the same lable on looping of timer


i need to loop using timer and want to display the output, but the condition is there should be only one label and using that i ve to split the words randomly hide them, use underscores for hidden lables, and now on looping through the timer i need to display the word in the database in the same place For eg: in first loop of timer:

MA_A_S
hint: HUMAN in second loop of timer: A_NIM_L_S
hint: TIGER etc..

the "words" with underscore is not being overridden... it comes as MA_A_S A_NIM_L_S

My create function is:

- (void)createbutton:(NSInteger)j {

     p = 30;

    x = x+p ;
    if(x>250) {
        x=35;
        y=y+70;
    }

    pLblMyLable1 = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 45, 45)];

    [pLblMyLable1 setTag:j+1];  
     iTag = [pLblMyLable1 tag];

    if (i == n|| i == r || i == s) {

        pLblMyLable1.hidden = YES;
            pLblUnderScore =[[UILabel alloc] initWithFrame:CGRectMake(x, y, 45, 45)];
            pLblUnderScore.backgroundColor = [UIColor clearColor];
            pLblUnderScore.text = @"_";
            pLblUnderScore.font = [UIFont fontWithName:@"Arial" size: 10.0];
            [pLblUnderScore setTag:2];  
            [self.view addSubview:pLblUnderScore];  

    } else {

        pLblMyLable1.hidden = NO;
    }

    pLblMyLable1.backgroundColor = [UIColor clearColor];
    pLblMyLable1.text = pStr;
    pLblMyLable1.font = [UIFont fontWithName:@"Arial" size: 10.0];
    [self.view addSubview:pLblMyLable1];    
    [pLblMyLable1 release];

}

Solution

  • Format your string according to your requirement. Use NSString to overWrite in same label's Text.

    To add string in same string use stringByAppendingFormat. How to do check this:

    NSString *str @"MA_MA_"
    YourLabel.text = str
    

    Now

    [str stringByAppendingFormat:@"ANI__L....."];
    YourLabel.text = str;
    

    Your label will display MA_MA_ANI__L.....