【发布时间】:2011-01-14 15:41:00
【问题描述】:
我正在使用 iPhone SDK (3.0),我正在尝试创建一个选择器数组来调用一个类中的各种方法。
显然,我做错了(我认为@selector 不被视为一个类,因此将它们填充到 NSArray 中是行不通的)。
我试过这个,但显然是错误的。
有没有一种简单的方法来拥有这样的选择器数组?或者有没有更好的方法来遍历一组方法?
selectors = [NSArray arrayWithObjects:
@selector(method1),
@selector(method2),
@selector(method3),
@selector(method4),
@selector(method5),
@selector(method6),
@selector(method7), nil];
for (int i = 0; i < [selectors count]; i++) {
if ([self performSelector:[selectors objectAtIndex:i]]) // do stuff;
}
【问题讨论】:
标签: ios objective-c nsarray selector