- (instancetype)initWithTitle:otherButtonTitles, ... {
NSMutableArray *buttonTitleArray = [NSMutableArray array];
va_list args;
va_start(args, otherButtonTitles);
if (otherButtonTitles) {
[buttonTitleArray addObject:otherButtonTitles];
while (1) {
NSString *otherButtonTitle = va_arg(args, NSString *);
if (otherButtonTitle == nil) {
break;
} else {
[buttonTitleArray addObject:otherButtonTitle];
}
}
}
va_end(args);
//...后面略
}
如代码,定义时加上...,这个写法可以参照UIActionSheet的初始化呀。
用的时候使用va_list循环获取。没去深究,就先记着这么用吧=。=
本文介绍了一段Objective-C代码中如何使用可变参数列表来动态接收多个按钮标题,并将其存储到NSMutableArray中。这种方法常见于UIActionSheet等组件的初始化过程中。
2397

被折叠的 条评论
为什么被折叠?



