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
의 초기화 프로그램으로 전달할 수 있습니까?
링크가 포함되어 있지 않습니까? – fabian789
오 예. 대기. – vikingosegundo
죄송합니다. 어제 긴 밤이었습니다 :) – vikingosegundo