Я создал кнопки динамически. Теперь я хочу получить значение индекса кнопки.
Вот мой код,
Например,
Мой массив,
{
one,
two,
three,
Four
}
int x = 10;
for(int i = 0; i < [myArray count]; i++) {
UIButton *answerBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[answerBtn setFrame:CGRectMake(30, x, 260, 40)];
answerBtn.tag = i;
[answerBtn setTitle:[answerList objectAtIndex:i] forState:UIControlStateNormal];
NSString *actualString = @"two";
NSString *getString = [answerList objectAtIndex:i];
if([actualString isEqualToString:getString])
{
//How do i get the correct values of array index, In this case i want to return the index value is 1. Bcoz the array[1] = two.
NSLog(@"The btn tag is %d", answerBtn.tag); // couldn't get correct index
}
[self.view addSubview: answerBtn];
}
Ожидаемый результат:
The btn tag is 1.