入力に応じてUIView
動的な数のオブジェクトを表示するカスタム クラスを作成したいと考えています。UISegmentedControl
たとえば、クライアントのカートに 5 つの製品がある場合、 は 5 つのオブジェクトをUIView
生成UISegmentedControl
し、それを各アイテムにリンクします。
私が抱えている問題は、これを で動作させることUIView
です。これが私がこれまでに行ったことです。UISegmentedControl
オブジェクトを正常に作成し、プログラムで main 内に表示できますUIViewController
。UIView
クラスに追加しても表示されません。UIView
クラスの実装コードは次のとおりです。
#import "ajdSegmentView.h"
@implementation ajdSegmentView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *itemArray = [NSArray arrayWithObjects:@"Yes", @"No", nil];
UISegmentedControl *button = [[UISegmentedControl alloc] initWithItems:itemArray];
button.frame = CGRectMake(35,44, 120,44);
button.segmentedControlStyle = UISegmentedControlStylePlain;
button.selectedSegmentIndex = 1;
[self addSubview:button];
}
return self;
}
@end
UIView
Storyboard で新しいオブジェクトを作成し、UIViewController
シーン内に配置しました。クラスをジェネリックUIView
クラスから新しいカスタム クラスに設定したことを確認しました。クラスUIView
にコンセントを追加しました。UIViewController
の実装内のコードは次のUIViewController
とおりです。
#import "ajdViewController.h"
@interface ajdViewController ()
@end
@implementation ajdViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.segmentView = [[ajdSegmentView alloc] init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
それが私が試したすべてです。私は多くのページを検索し、ここで質問せずにこれを実装しようとしましたが、間違った場所を探しているようです.