objective c - Get String From Array to call method -
i'm trying string in call array. have no luck. it's being passed class.
mainclass.h #import first @class first; @interface mainclass : uiviewcontroller{ nsmutablearray *listarray; } /////////////////// mainclass.m first *first = [[first alloc] init]; listarray = [[nsmutablearray alloc]init]; [listarray addobject:@"first"]; [listarray addobject:@"second"]; int aslot = 0; int suma; float level = 5, insample = 10; nsstring *slota =[listarray objectatindex:aslot]; suma = [slota out:insample andlevels:level]; ///////// first.h -(float)out:(float)insample andlevels:(float)level; first.m -(float)out:(float)insample andlevels:(float)level{ float outsample = insample + 10 * level; return outsample; }
i want slota (the class) equal string array "first" or "second", can call method.
i have table when select first, sends samples , other parameters class processing returns mainclass.
suma = [first out:insample andlevels:level];
but i'm getting error saying nsstring may not respond parameters out:andlevels. please help..
edit:
if understand correctly, want dynamically create instance of class name have stored nsstring
. can way:
int aslot = 0; int suma; float level = 5, insample = 10; nsstring *classname = [listarray objectatindex:aslot]; class sampler = objc_getclass([classname utf8string]); id instance = [[sampler alloc] init]; suma = [instance out:insample andlevels:level]; // whatever want suma here. [instance release];
if you're doing lot, you'll want either keep instance around or store classes in array instead of names, depending on doing.
Comments
Post a Comment