如何迭代方法調用,例如。objective C迭代方法調用
[self revertBox1];
[self revertBox2];
[self revertBox3];
[self revertBox4];
[self revertBox5];
// They are as many as 20.
example1 * xmp = [[example1 alloc] initWithNibName:@"example1" bundle:nil];
// How can I iterate the class instantiation example1, example2, example3
// If I use this method..
NSString *classNameStr = [NSString stringWithFormat:@"example%d", i];
Class cls = NSClassFromString(classNameStr);
cls *obj = [[[cls alloc] initWithNibName:classNameStr bundle:nil];
//I receive an error [ Use of undeclared identifier 'obj' ]
聰明,但user797819真的只是需求重新分解他的原始代碼和聲明。 –
@科爾曼斯塔維什,是的。他應該。 – EmptyStack
---- NSString * classNameStr = [NSString stringWithFormat:@「example%d」,i]; ---- Class cls = NSClassFromString(classNameStr); ---- cls * obj = [[[cls alloc] initWithNibName:classNameStr bundle:nil]; //使用未聲明的標識符'obj' –