スーパービューにサブビューを追加できるカスタムクラスを作成する方法を学ぼうとしていますが、以下のコードは機能するはずですが、そうではなく、理由を理解するのに十分な理解がありません。正常にビルドされ、サブビューの追加が実行されますが、シミュレーターには表示されません。私は誰かが私を正しい方向に向けることができることを望んでいました。
mainviewcontroller.mは#alerts.hをインポートし、実行を試みます
Alerts* al = [[Alerts alloc] initWithFrame:[self.view bounds]];
[al throwBottomAlert:@"message" withTitle:@"Title Test"];
そして私のカスタムクラスでは...
ヘッダーファイル
#import <UIKit/UIKit.h>
@interface Alerts : UIAlertView
- (void)throwBottomAlert:(NSString*)message withTitle:(NSString*)title;
@end
実装ファイル
#import "Alerts.h"
@implementation Alerts
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)throwBottomAlert:(NSString*)message withTitle:(NSString*)title {
UIView* alertView = [[UIView alloc] initWithFrame:[self bounds]];
alertView.backgroundColor = [UIColor blackColor];
[self.superview addSubview:alertView];
[self.superview bringSubviewToFront:alertView];
}