1

3 つの UIButton を持つ NSMutableArray と 50 の UIButton を持つ 2 つ目の NSMutableArray があります。これらの 3 つの UIButtons タイトルを取得して、SecondArray の各 UIButton に文字ごとに割り当てたいのですが、Second Array のこれらの 50 個の UIButtons のそれぞれには、すでに単一の Character.My Basics の目的があります。まず第一に、それぞれの長さを確認したいということです私の最初の配列の uibutton タイトル、それから 2 番目の配列の UIButton へのインデックスによってインデックスに割り当てます。 2番目の配列の0-5、13-16、35-38).3つのUIBttonsを持つ最初の配列.hereはコードです。

NSMutableArray *buttons = [NSMutableArray arrayWithObjects:btn1, btn2, btn3, nil];
            [btn1 setTitle:@"stack" forState:UIControlStateNormal]; 
            [btn2 setTitle:@"over" forState:UIControlStateNormal]; 
            [btn3 setTitle:@"flow" forState:UIControlStateNormal]; 

これが私のコードです。50個のUIButtonを作成します。

 -(void)button:(id)sender {
  saveBtn = [[NSMutableArray alloc] init];
  arr=[[NSArray alloc]
  initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",
     @"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil];

    for (int i=0; i<50; i++) {
            btn = [UIButton   buttonWithType:UIButtonTypeRoundedRect];
            btn.frame = CGRectMake(spacex, spacey, 30.0, 30.0);
            int idx;
            idx = arc4random()%[arr count];
            NSString* titre = [arr objectAtIndex:idx];
            [btn setTitle:titre forState:UIControlStateNormal];   
            spacex = spacex + 30;
            [saveBtn addObject:btn];
            [self.view addSubview:btn];

        }


            }

UIButtonのタイトルを特定のインデックスのこれらのUIButtonに割り当てる方法を教えてください。ありがとう

4

1 に答える 1

2

すべての人を助けてくれてありがとう..しかし、私はここでそれをやったのはコードです。

 - (void)getbuttontitle {
   for(int i = 0;i<[buttons count];i++)
  {
     if(i == 0)
    {
     UIButton *b1 = [buttons objectAtIndex:0];
      a = (NSString *)[[b1 titleLabel] text];
        [storewords addObject:a];
        NSLog(@"b=%@",a);
        }
    else if(i == 1)
    {

    }
    else if(i == 2)
    { 

    }
 }
}

    for (NSString *str in storewords) {
        if (str==a) {
            int j = 0;
            int randn= (arc4random()%5)+1 ;
            NSLog(@"n=%d",randn);
            for (int i=randn; i<[a length]+randn; i++) {
                NSLog(@"a=%@",a);
                NSString *ichar  = [NSString stringWithFormat:@"%c", [a characterAtIndex:j]];
                UIButton*  b = [saveBtn objectAtIndex:i];
                NSLog(@"a=%@",ichar);
                j++;
                [b setTitle:ichar forState:UIControlStateNormal]; 
            }   
        }

        if (str==c) {


        }   

        if (str==d) {

        }       
    }
于 2012-05-16T17:43:33.537 に答える