我想从字符串中设置uibutton等对象的名称。
NSString *buttonName = [[NSString alloc] initWithString:@"someString"];
我的目标是:
UIButton *someString = [[UIButton buttonWithType:UIButtonTypeCustom]retain];
我怎么解决这个问题?
在执行任何Objective-C代码之前,编译器就不能很好地解析变量名。你什么 可以 Do是使用 NSMutableDictionary :
NSMutableDictionary
NSString *string = @"someString"; [buttonMap setObject: [UIButton buttonWithType:UIButtonTypeCustom] forKey: string]; //...time passes... [[buttonMap objectForKey: @"someString"] setEnabled: YES];