View Full Version : AppDelegate - sending text from an UILabel
jjgraz
Mar 11, 2009, 06:41 PM
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:@"%f", mainDelegate.sli];
valueLBL.text = convert;
}
Thank you.
dejo
Mar 11, 2009, 06:53 PM
I tried to manipulate the code, but keep getting the error...(in something not a structure or union).
Which line of code from your snippets is giving you this error?
jjgraz
Mar 11, 2009, 08:00 PM
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
dejo
Mar 12, 2009, 12:19 AM
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.
jjgraz
Mar 12, 2009, 01:24 AM
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;
admanimal
Mar 12, 2009, 01:27 AM
sli is a double, name.text is an NSString. You can't make the assignment without converting the text to a double.
jjgraz
Mar 12, 2009, 01:31 AM
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.
jjgraz
Mar 12, 2009, 02:14 AM
Alright. It works decalred as an NSString in appDelegate with name.text. I appreciate your help guys.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.