-(instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
{
va_list args;
va_start(args, otherButtonTitles);
NSMutableArray *otherButtonsArray = [[NSMutableArray alloc] init];
for (NSString *arg = otherButtonTitles; arg != nil; arg = va_arg(args, NSString*))
{
[otherButtonsArray addObject:arg];
}
va_end(args);
if (POST_iOS8) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >70120
self = [super init];
alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
int buttonIndex = 0;
if(cancelButtonTitle)
{
CustomAlertAction *cancelAction =[CustomAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
if(delegate)
{
if ([delegate respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
[delegate alertView:self clickedButtonAtIndex:((CustomAlertAction*)action).buttonIndex];
}
}
}];
[cancelAction setButtonIndex:buttonIndex];
[alertController addAction:cancelAction];
buttonIndex++;
}
for (NSString *otherButton in otherButtonsArray)
{
CustomAlertAction *otherAction =[CustomAlertAction actionWithTitle:otherButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
if(delegate)
{
if ([delegate respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
[delegate alertView:self clickedButtonAtIndex:((CustomAlertAction*)action).buttonIndex];
}
}
}];
[otherAction setButtonIndex:buttonIndex];
[alertController addAction:otherAction];
buttonIndex++;
}
#endif
}
else
{
self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];
for (NSString *otherButton in otherButtonsArray)
{
[self addButtonWithTitle:otherButton];
}
}
return self;
}
我設計類Customalertview目標C instancetype方法有共同的代碼一起項目來顯示警報與標題,消息,按鈕標題,這是工作的罰款與客觀的C代碼。如何訪問迅速
但我想利用我迅速的項目之一相同的代碼,我無法調用此方法,並提供其他按鈕標題
注意,我無法訪問像
CustomAlertView.initWithTitle......
'CustomAlertView.initWithTitle ......' –
我想這是不工作@先生 – Vinodh
這個初始化程序來自UIAlertView,它從iOS 9開始不推薦使用。也許最好是隻用UIAlertController來代替它。從這個答案http://stackoverflow.com/a/24022764/1638166它似乎這個UIAlertView初始化器從未工作。 – johnyu