我试过下面的代码,但只有otherButtonTitles
的第一个出现。argumentList只显示一个
- (id)initWithCancelButtonTitle:(NSString *)cancelButtonTitle primaryButtonTitle:(NSString *)primaryButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [self init];
if (self)
{
// Build normal buttons
va_list argumentList;
va_start(argumentList, otherButtonTitles);
NSString *argString = otherButtonTitles;
while (argString != nil)
{
UIButton *button = [self buildButtonWithTitle:argString];
[self.buttons addObject:button];
argString = va_arg(argumentList, NSString *);
}
va_end(argumentList);
// Build cancel button
UIButton *cancelButton = [self buildCancelButtonWithTitle:cancelButtonTitle];
[self.buttons insertObject:cancelButton atIndex:0];
// Add primary button
if (primaryButtonTitle)
{
UIButton *primaryButton = [self buildPrimaryButtonWithTitle:primaryButtonTitle];
[self.buttons addObject:primaryButton];
}
// Add destroy button
if (destructiveButtonTitle)
{
UIButton *destroyButton = [self buildDestroyButtonWithTitle:destructiveButtonTitle];
[self.buttons insertObject:destroyButton atIndex:1];
}
}
return self;
}
如何修改?
如果您创建函数超过2-3的说法,我建议你创建一个字典作为该方法的参数和以前的说法应该是成员那本字典。因此,您的代码将易于阅读和维护良好 – Tirth 2013-04-09 10:13:49
我想知道我的代码为什么只给第一个。谢谢你的回答 – pengwang 2013-04-09 10:19:16
:D我还没有回答。我只是给你建议。 – Tirth 2013-04-09 10:21:27