iphone - 如何使用 Plist 中的标签添加动态创建的文本字段并获取值

标签 iphone objective-c ios

我想使用 plist 中的标签从动态创建的文本字段中添加并获取值...... 我怎样才能做到这一点?

Txt_New_Estimated = [[UITextField alloc]initWithFrame:CGRectMake(360, textPosY , 130, 65)];
Txt_New_Estimated.delegate = self;
Txt_New_Estimated.text=@"";
Txt_New_Estimated.tag = i; 
Txt_New_Estimated.clearButtonMode = UITextFieldViewModeWhileEditing;
[Txt_New_Estimated addTarget:self action:@selector(C6Loop)  forControlEvents:UIControlEventEditingChanged];//UIControlEventEditingDidEnd
Txt_New_Estimated.placeholder = @"Estimated";
Txt_New_Estimated.font = [UIFont fontWithName:@"Arial" size:23];
Txt_New_Estimated.backgroundColor = [UIColor whiteColor];
Txt_New_Estimated.textAlignment = UITextAlignmentCenter;
[scrollview addSubview:Txt_New_Estimated];
[textFieldArray addObject:Txt_New_Estimated];

如何添加带有这样的标签的对象...

[form1Array1 addObject:Txt_New_ONU.text];//3

我想添加标签上textfiled的每个索引的值......

如何添加、保存并通过 plist 检索 textfild 标记上的值...就像这一行

[form1Array1 addObject:Txt_New_ONU.text];//3

它将值保存在plist上的第三个位置...如何保存n检索标签上动态创建的文本字段的值,我的位置n如何检索它?

最佳答案

将 plist 的内容读取到数组:

// Path to the plist (in the application bundle)
NSString* path = [[NSBundle mainBundle] pathForResource:@"PlistFile" ofType:@"plist"];

// Build the array from the plist
NSMutableArray* arr = [[NSMutableArray alloc] initWithContentsOfFile:path];

迭代数组以创建带有标签的文本字段并将其添加到新数组中:

NSMutableArray* newArr = [NSMutableArray array];
for(int i=0; i<[arr count]; i++)
{
    UITextField field = [[UITextField alloc]initWithFrame...
    field.tag = i;
    (...) // other initialization code
    [newArr addObject:field];
}

关于iphone - 如何使用 Plist 中的标签添加动态创建的文本字段并获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9819970/

相关文章:

ios - 如何实现 Realtor iPad 应用程序中使用的自定义绘图搜索工具?

iPhone UITableView 错误??? -sectionIndexTitlesForTableView 似乎是造成的?

iphone - 从 Cydia 安装调整后重新启动

iphone - 推送 View Controller - 未调用 viewDidAppear

iphone - 如何为一组嵌套的 UIView animateWithDuration 调用调用单个完成 block ?

objective-c - Objective C self.variable 和变量赋值之间的区别

objective-c - 为什么进度指示器没有从 View Controller 类启动?

ios - Firebase 检查空值 (Swift)

iphone - TableViewDataSource 文件的运行时错误已分离

使用 UIwebview 显示使用 google maps api 的网页时,iOS 7 和应用程序崩溃