1

위임 대신 블록을 사용하는 UIActionSheet의 하위 클래스를 만들고 싶습니다.가변 인수 목록 전달

#import <UIKit/UIKit.h> 

// Public Interface 
typedef void (^FJActionSheetCompletion)(int buttonIndex); 

@interface FJActionSheet : UIActionSheet 

- (id)initWithTitle:(NSString *)title 
    completionBlock:(FJActionSheetCompletion)completionBlock 
    cancelButtonTitle:(NSString *)cancelButtonTitle 
destructiveButtonTitle:(NSString *)destructiveButtonTitle 
    otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; 

@end 

// Private Interface 
@interface FJActionSheet() <UIActionSheetDelegate> 
{ 
    FJActionSheetCompletion _completionBlock; 
} 
@end 

// Implementation 
@implementation FJActionSheet 

- (id)initWithTitle:(NSString *)title 
    completionBlock:(FJActionSheetCompletion)completionBlock 
    cancelButtonTitle:(NSString *)cancelButtonTitle 
destructiveButtonTitle:(NSString *)destructiveButtonTitle 
    otherButtonTitles:(NSString *)otherButtonTitles, ... 
{ 
    self = [super initWithTitle:title 
         delegate:self 
       cancelButtonTitle:cancelButtonTitle 
     destructiveButtonTitle:destructiveButtonTitle 
       otherButtonTitles:otherButtonTitles]; 

    if (self) 
    { 
     _completionBlock = [completionBlock copy]; 
    } 

    return self; 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    _completionBlock(buttonIndex); 
} 

@end 

이 하나의 문제를 제외하고 작동 : 나는 otherButtonTitles에 대해 여러 문자열을 전달할 수 없습니다 그래서 나는 다음과 같은 클래스를 만들었습니다. 위와 같이 할 경우, 나는 (분명히) "방법 파견에서 파수꾼이 없다"고합니다.

내 질문은 otherButtonTitles 인수를 UIActionSheet의 초기화 프로그램으로 전달할 수 있습니까?

답변

1

가변 방식에 관한 자세한 내용은 great blog post을 참조하십시오. 주로 변수 인수에 액세스하는 방법

va_list args; 
va_start(args, firstArg); 
va_arg(args, NSString*) 
+0

링크가 포함되어 있지 않습니까? – fabian789

+0

오 예. 대기. – vikingosegundo

+0

죄송합니다. 어제 긴 밤이었습니다 :) – vikingosegundo