1

Possible Duplicate:
object with the name of a string

I want to call the code below, but be able to change "itemInstance" with a stringe variable. Is this possible?

UIImage *image = [itemInstance getImage:itemNumber];

EDIT: I just read about the NSSelectorFromString method which appears to be what I need to use, but I have no idea how it's supposed to implemented. Any ideas?

4

2 回答 2

3

不完全是。获得这种效果的最简单方法是构建一个 NSDictionary,将字符串作为键,将匹配的实例作为值。然后它变成这样:

UIImage *image = [[dict objectForKey:instanceName] getImage:itemNumber];
于 2012-06-04T16:30:25.223 回答
0

我通过从 NSArray 中选择实例来解决它。我选择菲利普斯的答案是因为它让我到达了我需要到达的地方。

于 2012-06-04T18:11:34.540 回答