0

だから私がやろうとしているのは、ボタンを押すたびに、作成した UIScrollView に新しい画像ビューを追加する画面を表示することですが、問題が発生しました... uiscrollview が viewDidLoad で作成されたためです後のメソッドで使用するために宣言されていません...だから私の質問は基本的に...どうすればこれを回避できますか?

int pixels = 20;
int playerCount = 2;
-(void) viewDidLoad{

UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
mainScroll.contentSize = CGSizeMake(320, 700);
mainScroll.showsHorizontalScrollIndicator = YES;
[self.view addSubview:mainScroll];
[mainScroll setScrollEnabled:YES];


UIButton *addPlayersButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];

[addPlayersButton addTarget:self
                     action:@selector(addPlayer)
           forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview: addPlayersButton];
    addPlayersButton.frame = CGRectMake(20, pixels, 50, 50);



-(void)addPlayer{
pixels += 90;
playerCount++;

if (playerCount <= 7) {
    UIImageView *player3 = [[UIImageView alloc]initWithFrame: CGRectMake(15, pixels, 290, 80)];
    player3.image = [UIImage imageNamed:@"player1Bar.png"];
    [mainScroll addSubview:player3];
}
4

1 に答える 1

0

私がする必要があるのは、UIScrollView を .h ファイルに作成し、それを合成して複数のメソッドで使用できるようにすることであることがわかりました。

于 2012-05-27T00:17:39.697 に答える