开发者

What is wrong with this syntax?

I have #imported the FirstViewController.h

and i get the error "expected ':' before '.' token"

NSString *myString = RoutineTitle.text;

[FirstViewController.routines addObject:myString];

What am i doing wrong? Someone please enlighten开发者_如何学JAVA me!

Thanks,

Sam


Is "routines" a member of FirstViewController? It sort of looks like "FirstViewController" is a class name, not an instance name, but I could be mistaken.

If you are in "FirstViewController", and "routines" is a variable in scope that is an NSArray or NSMutableArray or similar, just change it to:

NSString *myString = RoutineTitle.text;

[routines addObject:myString];


The syntax

[FirstViewController.routines addObject:myString];

is used in languages (I think other than objective c not in objective c) to assign values to static variables.

So if routines is an object of a static array you should define a static method in the FirstViewController class and calling that method you should add this object like:

+(void)addObjectToRoutines:(NSString *)string{//In the FirstViewController class
[routines addObject:string];
} 

and from the class you are in just do this

NSString *myString = RoutineTitle.text;

[FirstViewController addObjectToRoutines:myString];

Now if its a stance variable you should first make a object of your class like:

FirstViewController *viewCont = [[FirstViewController alloc] init];
[[viewCont routines] addObject:myString];

Hope this helps.(The answer is given as my pridiction is that FirstViewController is class name not a variable, may be I am mistaken)

Thanks,

Madhup


From the import statement I assume that FirstViewController is the name of a class:

#imported the FirstViewController.h

You are possibly trying to access a variable inside that class which should be some kind of collection supporting addObject::

[FirstViewController.routines addObject:myString];

However you need to use the object name not the class name, something like (I don't know how your code looks like):

FirstViewController * aFirstViewController
            = [[FirstViewController alloc] initWithSomething ....];

Now assuming that FirstViewController has a collection routines and appropriate property declaration you could do:

[aFirstViewController.routines addObject:myString];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜