1

関連する TagDisplayCell.m を持つ TagDisplayCell.xib があります。ファイルでは、.mそのようにビューをロードします。

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder: aDecoder];
    if(self){
        //load the interface file from .xib
        [[NSBundle mainBundle] loadNibNamed:@"TagDisplayCell" owner:self options:nil];

        //add as subview
        [self addSubview:self.view];

        self.view.translatesAutoresizingMaskIntoConstraints = NO;

        [self addConstraint:[self pin:self.view attribute:NSLayoutAttributeTop]];
        [self addConstraint:[self pin:self.view attribute:NSLayoutAttributeLeft]];
        [self addConstraint:[self pin:self.view attribute:NSLayoutAttributeBottom]];
        [self addConstraint:[self pin:self.view attribute:NSLayoutAttributeRight]];
    }

    return self;
}

私のView Controllerには垂直がありますUiStackView(コンテンツが行に積み重ねられるように)。TagDisplayCellこの UiStackViewに のインスタンスをいくつか追加したいと考えています。これが私がやっていることです。

//create all the views 
for(int i=0; i<[commentsAndTagsArray count]; i++)
{
    NSObject *obj =commentsAndTagsArray[i];
    if ([obj isKindOfClass:[Tag class]])
    {
        Tag *tempTag = ((Tag*) obj);
        TagDisplayCell *tempTagCell = [[TagDisplayCell alloc] initWithFrame:frame];
        [uiStackView addSubview:tempTagCell];
    }
}

これを実行すると、画面に何も表示されません。ここで何が欠けていますか?

更新: ここに私の TagDisplayCell.xib があります" ここに画像の説明を入力

4

1 に答える 1

0

View サブクラスを呼び出しinitWithFrame:た場合、XIB からロードされません。

最初のコード スニペットで行ったのと同じ方法で、ビューの読み込みを実行します。

TagDisplayCell *tempTagCell = (TagDisplayCell *)[[[NSBundle mainBundle] loadNibNamed:@"TagDisplay" owner:nil options:nil] firstObject];
于 2015-11-01T18:09:27.367 に答える