Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
UIButton * button = [self valueForKey: [NSString stringWithFormat: @"buttonA"];
有没有办法做同样的事情而不必使用“自我”这个词?
self是类的当前实例。
self
这是最好的方法。
除了 self 之外,您还需要创建该对象的另一个实例并使用该对象。
MyClass *classObject=[MyClass new]; UIButton * button = [classObject valueForKey: [NSString stringWithFormat: @"buttonA"];