AppDelegate - sending text from an UILabel

Discussion in 'iOS Programming' started by jjgraz, Mar 11, 2009.

  1. jjgraz macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #1
    I have recently completed an exercise using two views, and the appDelegate to display a slider Value on a label on a different view from the slider itself. (label is updated with a refresh button.) It all works fine. Now i want to do the same thing, only send text from one view to the other. I tried to manipulate the code, but keep getting the error...(in something not a structure or union). Below is a snip of code of the action which dismisses the view and pulls the slider value.....I rather it pulled just a plain old UILabel and displayed the same text in my other UILabel in second view. Please let me know if you can help sort me out.

    -(IBAction)returnToMainView{
    XXXXAppDelegate *mainDelegate = (XXXXAppDelegate *)[[UIApplication sharedApplication]delegate];

    mainDelegate.sli = slider.value;

    [self dismissModalViewControllerAnimated:YES];
    }



    In second View where the value is retrieved:

    -(IBAction)refresh{
    XXXXAppDelegate *mainDelegate = (XXXXAppDelegate *)[[UIApplication sharedApplication]delegate];

    NSString* convert = [NSString stringWithFormat:mad:"%f", mainDelegate.sli];

    valueLBL.text = convert;

    }

    Thank you.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Which line of code from your snippets is giving you this error?
     
  3. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #3
    after the thing was working with the slider....I made another outlet for a UILabel hoping to just pass the text through to the other view into another label(example below.....name)....and the error pops up...

    -(IBAction)returnToMainView{
    XXXXAppDelegate *mainDelegate = (XXXXAppDelegate *)[[UIApplication sharedApplication]delegate];

    mainDelegate.sli = name.value;

    Error: request for member 'value' in something not a structure or union.

    [self dismissModalViewControllerAnimated:YES];
    }

    also tried: name.text
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    If 'name' is a UILabel, it doesn't have a 'value' property. Try 'text' instead.

    P.S. It's a good idea to check the class references to find out what properties and methods are available to use.
     
  5. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #5
    name is actually a UILabel. I did already try name.text, as it was the first thing that came to mind....however,.....it comes back with error: incompatible type for argument 1 of 'setSli.

    -(IBAction)returnToMainView{
    XXXXAppDelegate *mainDelegate = (XXXXAppDelegate *)[[UIApplication sharedApplication]delegate];

    mainDelegate.sli = name.text;

    ERROR: incompatible type for argument 1 of 'setSli.

    [self dismissModalViewControllerAnimated:YES];
    }


    When I set up the variable Sli in appdelegate.....I did it as a double...see below.

    double sli;
    .......more code.....

    @property (nonatomic) double sli;

    Is this why i'm being told its an incompatable type? I understand double is used for integers, but what is the alternative within the appDelegate for just passing through a text variable? It doesn't work if i type just IBOutlet sli;
    should it be a NSString you think? IBoutlet NSString sli;
     
  6. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #6
    sli is a double, name.text is an NSString. You can't make the assignment without converting the text to a double.
     
  7. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #7
    can I make it easy on myself and make sli a NSString instead, eliminating any need for converting? Thus making the name.text pass through the appdelegate seemlessly. There really is no need for values.
     
  8. jjgraz thread starter macrumors regular

    jjgraz

    Joined:
    Feb 13, 2009
    #8
    Alright. It works decalred as an NSString in appDelegate with name.text. I appreciate your help guys.
     

Share This Page