1

コードを使用して UIView (たとえば A) オブジェクトを作成し、コードを使用して UIButton、UILabel などのすべてのサブビューを追加しました。XIB で作成したもう 1 つの UIView (たとえば B)。現在、A を B に割り当てようとしています。割り当て後に B のサブビューをログに記録すると、B に A のすべてのサブビューが表示されますが、ビューには何も表示されません。私の論理が間違っている可能性があることはわかっていますが、理解できませんでした。可能か不可能か教えてください!

これが私のコードです:

- (UIView*)createButtonView:(NSInteger)viewTag avatarImageName:(NSString*)avatarImageName cardImageName:(NSString*)cardImageName ballImageName:(NSString*)ballImageName
{
    buttonBGView = [[UIView alloc] initWithFrame:CGRectMake(15,86,290,290)];
    buttonBGView.tag = viewTag;

    UIImageView *avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 206, 84, 84)];
    avatarImageView.image = [UIImage imageNamed:avatarImageName];
    [buttonBGView addSubview:avatarImageView];

    UIButton *temoCardButton  = [[UIButton alloc] initWithFrame:CGRectMake(58, 42, 188, 222)];
    temoCardButton.tag = viewTag;
    [temoCardButton setImage:[UIImage imageNamed:cardImageName] forState:UIControlStateNormal];
    [temoCardButton addTarget:self action:@selector(cardButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [buttonBGView addSubview:temoCardButton];

    UILabel *scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(228, 0, 30, 30)];
    scoreLabel.text = [cardPointsArray objectAtIndex:randomIndex];
    scoreLabel.textAlignment = UITextAlignmentCenter;
    [buttonBGView addSubview:scoreLabel];

    buttonBGView.backgroundColor = [UIColor redColor];

    return buttonBGView;
}


-(void)cardButtonTapped:(id)sender
{
    NSLog(@"%@",[buttonBGView subviews]);

    self.cardTappedView = buttonBGView;

    NSLog(@"%@",[self.cardTappedView subviews]);
}

ありがとう

4

0 に答える 0