Link to home
Start Free TrialLog in
Avatar of charmingduck
charmingduck

asked on

for loop in objective c

how do I output this in using a for loop in objective c?

  [self.window addSubview:button];
    [self.window addSubview:button2];
    [self.window addSubview:button3];
    [self.window addSubview:button4];
    [self.window addSubview:button5];
    [self.window addSubview:button6];
    [self.window addSubview:button7];
    [self.window addSubview:button8];
    [self.window addSubview:button9];
    [self.window addSubview:button10];
Avatar of Hamidreza Vakilian
Hamidreza Vakilian

If you need prompt answers you might consider increasing the points to 500 on your questions, although your questions are not difficult but the explanation is somehow difficult since it sounds you are just beginning iOS development.
Avatar of charmingduck

ASKER

400 is sufficient, please help.
SOLUTION
Avatar of Hamidreza Vakilian
Hamidreza Vakilian

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and how do I not create 10 buttons manually?
Then you may try this:

for (int i =0; i != 0; i++) {
 UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(20, 20 + i*25, 100, 20); // position in the parent view and set the size of the button
    [myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
[self.window addSubview:myButton];
}

Open in new window

hmm, I dont think this code works, and I did try, it didn't.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial