Hi everyone!
I'd like to display 16 button with a title of number between 1 and 8. The titles will be assigned by chance, but a number will appear only twice.
My code is as follows. When I compile it, while it is blank on the simulator.
A line (on the r = r-1) advised me : assignment makes integer from pointer without a cast
I hope as i was clear, thank you to be good enough help me.
I'd like to display 16 button with a title of number between 1 and 8. The titles will be assigned by chance, but a number will appear only twice.
My code is as follows. When I compile it, while it is blank on the simulator.
A line (on the r = r-1) advised me : assignment makes integer from pointer without a cast
Code:
- (void)viewDidLoad {
[super viewDidLoad];
int myRand, a, r;
a=0; //initialize a
NSArray * test = [[NSArray alloc] init]; //Table for testing the random
for (int i=0; i<=3; i++){
for (int j=1; j<=4; j++){
r=2;
while (r!=0){
myRand = 1+arc4random() % 9;
for(int k=0; k=a; k++){
if(myRand=[test objectAtIndex:k]){
r=r-1;
}
}
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake((40+(i*60)),(j*60), 50, 50);
[myButton setTitle:[NSString stringWithFormat: @"%d",myRand] forState:UIControlStateNormal];
myButton.tag =myRand;
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
r=1;
}
}
}
}