-(IBAction)button:(id)sender
{
button = [UIButton buttonWithType:UIBarButtonSystemItemRefresh];
NSLog(@"Value of txtfrequency in button fuinction :%@",txtfrequency.text);
int z = [txtfrequency.text intValue];
NSLog(@"Value of z is :%d",z);
int y = 10;
//create a new dynamic button
for (int j=0; j<z; j++)
{
CGRect frame = CGRectMake(20, y , 50, 30);
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTag:j];
button.frame = frame;
CGRect frame1 = CGRectMake(100, y , 50, 30);
textFieldRounded = [[UITextField alloc] initWithFrame:frame1];
textFieldRounded.borderStyle =UIButtonTypeInfoDark; //UITextBorderStyleNone;
textFieldRounded.textColor = [UIColor blackColor]; //text color
textFieldRounded.font = [UIFont systemFontOfSize:17.0]; //font size
textFieldRounded.backgroundColor = [UIColor whiteColor]; //background color
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textFieldRounded.keyboardType = UIKeyboardTypeDefault; // type of the keyboard
textFieldRounded.returnKeyType = UIReturnKeyDone; // type of the return key
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldRounded.delegate = self;
[textFieldRounded setTag:j];
//[[scroll viewWithTag:j] removeFromSuperview];
[button reloadInputViews];
[textFieldRounded removeFromSuperview];
//[scroll
[scroll addSubview:button];
scroll.contentSize= CGSizeMake(100, 1400);
[scroll addSubview:textFieldRounded];
y= y+50;
}
}
Hii ..
Выше кода динамически не генерирует кнопок, когда пользователь вводит данные для кнопок. Но есть проблема в этом случае .. например Пользователь дал ввод для генерации 4 кнопок. Затем на экране мы видим 4 кнопки, но теперь, если пользователь хочет иметь только 2 кнопки, то на экране остаются 4 кнопки. Я не могу отослать или обновить действие кнопки.
Кто-нибудь знает, как я могу это сделать.
Пожалуйста, помогите мне.
Большое спасибо.