含む "のUIViewController + Alert.hを" ファイルを作成します "の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
が含まれていること:
#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を言います.H」:中続い
#import <UIKit/UIKit.h>
#import "UIViewController+Alert.h"
@interface SampleViewController : UIViewController
@end
"SampleViewController.m":
#import "SampleViewController.h"
@implementation SampleViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self showNoHandlerAlertWithTitle:@"Hello" andMessage:@"World"];
}
@end
お楽しみください!
ここにコードを入れてください –
これはカテゴリの権利ですか?次に、UIViewControllerのサブクラス化されたオブジェクトに.hファイルをインポートするだけです。 – Larme
.hファイルをカスタムビューコントローラにインポートする機能しません。拡張メソッドは利用できません。 – user267140