【问题标题】:How to add and fetch the Value From dynamically created textfiled with tag from Plist如何使用 Plist 中的标签从动态创建的文本字段中添加和获取值
【发布时间】:2012-03-22 10:00:40
【问题描述】:

我想使用 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

我想在标签上添加文本文件的每个索引的值......

如何添加,保存n通过plist检索textfild标签上的值......就像这一行

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

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

【问题讨论】:

    标签: iphone objective-c ios


    【解决方案1】:

    将 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];
    }
    

    【讨论】:

    • 这对我来说不起作用,先生,请提供其他想法...拜托。
    • 好的,到底是什么不适合你?有编译器错误吗?标签是否保存不当?由于某种原因,您不能使用此解决方案?
    • 您可以添加日志以查看您存储和取回的值吗?或者调试的时候能看到数值吗?
    • 先生,您的代码现在工作正常,我在我的代码中更改了一些内容并再次尝试您的代码,现在它工作正常......非常感谢先生...... Gr888 帮助...... .
    • 太棒了!如果它解决了您的问题,您能否考虑将我的回复标记为答案?
    猜你喜欢
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多