In my view, i have 12 buttons,and a array contains 6 names , i want to print the array names in UIButton
title. Here's my code:
texts = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",nil];
UIButton *button;
NSString *name;
NSUInteger count = [texts count];
int i=0;
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
button= (UIButton *)view;
if(button.tag >= 1||button.tag <= 20)
{
int value = rand() % ([texts count] -1) ;
int myTag= i+1;
button = [self.view viewWithTag:myTag];
name=[NSString stringWithFormat:@"%@",[texts objectAtIndex:value]];
[button setTitle:name forState:UIControlStateNormal];
NSLog(@"current name :%@",name);
}
i++;
}
}
[super viewDidLoad];
The problems I am facing are:
While shuffling the values are repeating,i tried with What's the Best Way to Shuffle an NSMutableArray?, its not working.
I want 6 titles in 12 button that means each title will be in 2 buttons. Please help me solve this issue. What changes should I make?