Я хочу установить имя объекта типа UIButton из строки.
NSString *buttonName = [[NSString alloc] initWithString:@"someString"];
Моя цель:
UIButton *someString = [[UIButton buttonWithType:UIButtonTypeCustom]retain];
как я могу решить это?
Вы не можете - имена переменных разрешаются компилятором задолго до того, как будет выполнен любой код Objective-C. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *. NSString *string = @"someString"; [buttonMap setObject: [UIButton buttonWithType:UIButtonTypeCustom] forKey: string]; //...time passes... [[buttonMap objectForKey: @"someString"] setEnabled: YES];
NSString *string = @"someString"; [buttonMap setObject: [UIButton buttonWithType:UIButtonTypeCustom] forKey: string]; //...time passes... [[buttonMap objectForKey: @"someString"] setEnabled: YES];