Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lolko

macrumors newbie
Original poster
Jan 28, 2010
4
0
i have class1 and class2.
im tryin to use Appdelegate to transfer info from class1 to class2,like that:

http://www.iphonedevsdk.com/forum/i...ing-variables-parameters-between-classes.html



have this problem:

1st class:
Code:
#import "MyAppDelegate.h"

@interface class1:UIViewController{

MyAppDelegate * mainDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;

//and other blablabla
}

p.s.:without it all works.


syntax error: expected ':', ',', ';' , '}' or "_Attribute_" before '=' token


why ?
 
You don't use braces when defining methods for '@interface' directives. They need to be in the form:

Code:
@interface SomeClass : SomeSuperclass {
/* IVars go here */

}

/* Method prototypes go here */

@end
 
ok.
forget about that.

1)i included MyAppDelegate.h in my class1.h file.
next, i have a method, connected to button in class1


2)Now, i tried to do it in 2 ways
a)

declaring in class1.h file
Code:
MyAppDelegate * mainDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;

if i make so, i have a syntax error (u can see it at the top)



b)
Declaring
Code:
MyAppDelegate * mainDelegate;
in class1.h file
(no syntax errors after that)

Code:
mainDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;

Code:
mainDelegate.MyLabel.text = @"ASDASDASD";
or
Code:
[mainDelegate.Mylabel setText:@"asdasd"];

in my class1.m file, in the method what im using

I have an UILabel called MyLabel in MyAppDelegate class.
and im receiving an "error :accessing unknown "MyLabel" getter method"




i need this to transfer some information from class1 to class2.
I want to put some text in this MyLabel of MyAppDelegate in class1 and after that retrieve some text from this MyLabel of MyAppDelegate in class2.



two questions : why i have syntax error in a)
and how to access this label in delegate class, if i should chose b) way
 
Code:
@interface class1:UIViewController{

MyAppDelegate * mainDelegate = (MyAppDelegate*)[UIApplication sharedApplication].delegate;
You can't do assignments in the interface.
 
Have you defined them as properties?

Incidentallly this is really bad design. You shouldn't be accessing UI components from all over the place. There are reasons the frameworks are designed the way they are and one is to encourage a proper MVC design. You should really put UI related stuff in a view controller not the app delegate.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.