CustomView.xib 파일을 사용하여 CustomView : UIView를 만듭니다. 이제 뷰를 다른 XIB (예 : UIViewController.xib)로 드래그하여 사용하고 class : customView를 선택하려고합니다.다른 XIB에서 클래스를 지정할 때 CustomView.xib로 CustomView를로드하는 방법?
내가 anotherView에있는 CustomView와 addSubView init을 때이 성공적으로로드 할 수 있습니다 경우
- (void)viewDidLoad{
//Success load NIB
CustomView *aView = [[CustomView alloc] initWithFrame:CGRectMake(40, 250, 100, 100)];
[self.view addSubview:aView];
}
//CustomView.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"INIT");
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
[[nib objectAtIndex:0] setFrame:frame];
self = [nib objectAtIndex:0];
}
return self;
}
지정한 다음 다른 XIB로 그리기에 의해 CustomCell을 재사용 클래스를 CustomView로 설정합니다. awakeFromNib가 호출되었지만 CustomView.xib를로드하는 방법을 알지 못합니다. 어떻게 그럴 수 있습니까?
* 편집 :
initWithCoder도 클래스를 지정하지만 loadNibNamed와 루프와 충돌을 생성 할 때 호출된다. 왜?
- (id)initWithCoder:(NSCoder *)aDecoder{
if (self = [super initWithCoder:aDecoder]) {
NSLog(@"Coder");
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"QSKey" owner:nil options:nil];
[[nib objectAtIndex:0] setFrame:self.bounds];
self = [nib objectAtIndex:0];
}
return self;
}
당신이 실제로 원하는 것을 ... 당신을받지 ?? –
CustomView를 xib와 함께로드하고 initWithFrame을 사용하지 않고 다른 Xib로 뷰를 드래그 한 다음 class.But을 지정하면 XIB가로드되지 않습니다. –
나는 이것이 네가하고 싶은 일이라고 생각 하나? http://stackoverflow.com/a/5096476/840428 – followben