label.hidden = YES inside a void

Discussion in 'iOS Programming' started by carvalhaes133, Aug 28, 2010.

  1. carvalhaes133 macrumors newbie

    Joined:
    Aug 27, 2010
    #1
    hi!
    inside a void i have a lot of things (like a printf) and they works fine.
    but when i try to put "label.hidden = YES;" the label dont become invisible.

    and when i put "label1000.hidden = YES;" inside an ibaction, it works. does anyone knows how to fix it?

    .h
    Code:
    ...
    UILabel *label;
    ...
    @property (nonatomic, retain) IBOutlet UILabel *label; 
    ...

    .m
    Code:
    ...
    @synthesize label;
    ...
    -(void)changeVisibility {
    label.hidden = YES;
    }
    ...
    
    thanks!
     
  2. zerocustom1989 macrumors regular

    Joined:
    Sep 5, 2007
    #2
    I think i ran into this... try

    [self.label setHidden:YES];

    or self.label.hidden = YES;
     
  3. carvalhaes133 thread starter macrumors newbie

    Joined:
    Aug 27, 2010
    #3
    thanks but it doesnt work.
    i dont understand why label.hidden works on a IBaction and dont work at a void.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Post the code that doesn't work. We can't debug descriptions of code.

    If your changeVisibility method isn't being called from somewhere else, then it won't execute by itself. If it is being called from somewhere else, we need to see that code.
     
  5. carvalhaes133 thread starter macrumors newbie

    Joined:
    Aug 27, 2010
    #5
    .main
    Code:
    #import <UIKit/UIKit.h>
    #import "MyViewController.h"
    int main(int argc, char *argv[]) {
    	MyViewController * start1000 = [[MyViewController alloc] init];
    	[start1000 onTimer1000];
    	
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, nil, nil);
        [pool release];
        return retVal;
    }
    
    
    .h
    Code:
    @interface MyViewController : UIViewController {
        NSTimer *Timer1000;
    	
    	int Times1000;
    	int valor;
    
    	
    	UIButton *button1;
    	IBOutlet UILabel *label1000;
    
    }
    -(void)onTimer1000;
    
    -(void)changeVisibility1000;
    
    @property (nonatomic, retain) IBOutlet UIButton *button1;
    @property (nonatomic, retain) IBOutlet UILabel *label1000;
    
    
    - (IBAction)changeGreeting:(id)sender;
    @end
    
    .m
    Code:
    #import "MyViewController.h"
    
    @implementation MyViewController
    
    @synthesize label1000;
    
    
    -(void)changeVisibility1000 {
    	if (Times1000 ==1) {
    		Times1000 = 0;
    		label1000.hidden = YES;
    		printf("a");
    	}
    	else
    	{
    		Times1000 = 1;
    		label1000.hidden = NO;
    		printf("b");
    	}
    
    }
    
    -(void)onTimer1000 {
    	Timer1000 = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeVisibility1000) userInfo:nil repeats:YES];
    }
    
    
    - (IBAction)changeGreeting:(id)sender {
    \\just for test this line bellow		
    label1000.hidden = YES;
    
    
    	if (valor==1) {
    		printf("1");
    		valor=0;
    		[button1 setTitle:@"Stop" forState:UIControlStateNormal];
    	}
    	else {
    		printf("0");
    		valor=1;
    		[button1 setTitle:@"Start" forState:UIControlStateNormal];
    	}
    	
    
    
      
    }
    
    
    - (void)dealloc {
    //   [label release];
    //    [string release];
        [super dealloc];
    }
    
    
    i want a program where a label appear and disappear with the frequency of one second, and a button which will stop the timer
    (i will do the button function after sold the problem of this thread).

    i can see in the debug "abababababababababa" (that means that the timer its working fine). but the label stills visible all the time. i put a "label1000.hidden = YES;" inside the button just to see if the label became invisible if i press the button, and it works.

    i just want to make the label invisible inside the void changevisibilty1000 (and not at ibaction changegreeting)

    SORRY FOR MY ENGLISH AND THANKYOU
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
  7. carvalhaes133 thread starter macrumors newbie

    Joined:
    Aug 27, 2010
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    UIButton is a subclass of UIView.
    Therefore, every UIButton has all the methods of UIView.

    Find the class reference doc for UIView.
    Google search terms: UIView class reference site:developer.apple.com

    Find the setNeedsDisplay method's description in that doc.
    Read the description.

    In your current code, find where you change the state of the button's hidden property.
    At each place, also tell the button setNeedsDisplay.
    Compile and run.
    See if anything changes.

    If nothing changes, post the revised code.
     
  9. carvalhaes133 thread starter macrumors newbie

    Joined:
    Aug 27, 2010
    #9
    I only want the timer that starts at the beginning of the program to modify the property "hidden" from label1000.
    the button is working perfectly and he is not part of this thread.
    (A function to stop I will create later).
    but thanks anyway
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #10
    Apply the same procedure to your UILabel. A UILabel is also a subclass of UIView.

    That is, when you change the UILabel's hidden property, also tell it setNeedsDisplay.
     
  11. carvalhaes133 thread starter macrumors newbie

    Joined:
    Aug 27, 2010
    #11
    all right. i read more of 30 pages about setNeedDisplay but i dont understand how to apply that to my code.

    i try to put
    Code:
    [label1000 setNeedDisplay];
    after the label1000.hidden = yes but still doesn't work...
    you already help me, but could you try to do that for me:eek:?
    i past a lot of hours tryng to make it
     

Share This Page