표준 사용자 정의 방법으로 표준 UIViewController
을 확장하려고합니다.UIViewController extension
#import <UIKit/UIKit.h>
@interface UIViewController (UIViewControllerExtension)
- (void) showNoHandlerAlertWithTitle:(NSString *)title andMessage: (NSString*)message;
- (void) showAlertWithTitle:(NSString *)title andMessage:(NSString*)message buttonTitles:(NSArray<NSString *>*)titles andHandler:(void (^)(UIAlertAction * action))handler;
@end
확장 된 UIViewController
은 어떻게 사용할 수 있습니까? 내 사용자 정의보기 컨트롤러를 상속 한 UIViewController
에서 상속해야합니다.
#import "UIViewController+Alert.h"
@implementation UIViewController (AlertExtension)
- (void) showNoHandlerAlertWithTitle:(NSString *)title andMessage: (NSString*)message {
// Insert code here
}
- (void) showAlertWithTitle:(NSString *)title andMessage:(NSString*)message buttonTitles:(NSArray<NSString *>*)titles andHandler:(void (^)(UIAlertAction * action))handler {
// Insert code here
}
@end
에서 당신의 "SampleViewController 말 : 파일 포함"의 UIViewController + Alert.m "를 만든 다음
#import <UIKit/UIKit.h>
@interface UIViewController (AlertExtension)
- (void) showNoHandlerAlertWithTitle:(NSString *)title andMessage: (NSString*)message;
- (void) showAlertWithTitle:(NSString *)title andMessage:(NSString*)message buttonTitles:(NSArray<NSString *>*)titles andHandler:(void (^)(UIAlertAction * action))handler;
@end
을 :
여기에 코드를 입력하십시오. 코드 –
의 이미지가 아닙니다. 맞습니까? 그런 다음 .h 파일을 UIViewController 하위 클래 싱 된 객체로 가져옵니다. – Larme
.h 파일을 사용자 지정보기 컨트롤러로 가져 오는 기능이 작동하지 않습니다. 확장 메서드를 사용할 수 없습니다. – user267140