如何解决释放标签中的文本
| 嗨... 我正在制作一个iphone应用程序,在该应用程序中我已使用循环概念以编程方式生成了按钮。但是,每当我输入按钮的值时,它就会得到修复,我们无法更改按钮的数量。我想更改按钮的数量该怎么做。任何人都有解决方案。 请帮我。 非常感谢。 代码是:-(IBAction)button:(id)sender
{
int z = [txtfrequency.text intValue];
NSLog(@\"Value of z is :%d\",z);
//int x = 20;
int y = 250;
//create a new dynamic button
for (int j=0; j<z; j++)
{
CGRect frame = CGRectMake(20,y,50,30);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//[button setTitle:@\"Button x\" forState:UIControlStateNormal];
[button setTag:j];
button.frame = frame;
CGRect frame1 = CGRectMake(100,30);
/*UITextField *label = [[UITextField alloc]initWithFrame:frame1];
//[button setTitle:@\"Button x\" forState:UIControlStateNormal];
[label setTag:j];
label.frame = frame1;*/
UITextField * textFieldRounded = [[UITextField alloc] initWithFrame:frame1];
textFieldRounded.borderStyle = 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];
[button reloadInputViews];
[textFieldRounded removeFromSuperview];
[scroll addSubview:button];
[scroll addSubview:textFieldRounded];
y= y+50;
}
}
解决方法
添加新按钮之前,您需要先删除现有按钮,否则最终将它们堆积起来。最终它将耗尽内存。您可以为容器视图分配相同的标签,而不是为按钮和文本字段分配相同的标签。以后,您可以删除子视图并显示“ 1”。
由于它们似乎是行,因此您也可以通过查看
UITableView
来简化此过程,每行包含一个按钮和文本字段。对于表视图,更改行数(这是您想要的)与更改数据源返回的数一样简单。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。