【发布时间】:2011-06-02 06:49:06
【问题描述】:
-(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;
}
}
嗨..
每当用户输入按钮时,上述代码不会动态生成按钮。但是在这个事件中有问题......例如用户已经给出了生成 4 个按钮的输入。然后在视图中我们得到 4 个按钮,但是现在如果用户想要只有 2 个按钮,那么仍然有 4 个按钮在视图中。我无法引用或更新按钮的操作。
任何人都知道我该怎么做。
请帮帮我。
非常感谢。
【问题讨论】:
标签: iphone objective-c ios uibutton