【问题标题】:display ARRAY values in textfield?在文本字段中显示数组值?
【发布时间】:2014-04-08 13:40:12
【问题描述】:

您好,我正在使用 Xcode 中的 mysql 数据库创建学生详细信息,当我在文本字段中输入学生姓名时,希望在表单中显示学生信息。我已经在 J​​SON 数组中获得了 mysql 数据并存储在 NSMutable 数组中。现在我想在每个文本字段中获取数组值。这可能吗? 提前致谢。 我在 NSLOG 中的数组值:

    (
    {
    firstName = hari;
    lastname = krishna;
    age=10;
    fathername=ragav;
    },
    {
    firstName = priya;
    lastname = amirtha;
    age=8;
    fathername=ravi;
    }
    )

【问题讨论】:

  • 是您在 UITableView 或其他地方的 UITableViewCell 中每个学生信息的每个文本字段吗?请告诉我们。它会帮助我们。
  • 我在 UIviewcontroller 中有每个信息的文本字段。
  • ok 表示在一个 nib 文件中。您正在显示所有学生的详细信息。我对吗?。请指导我们

标签: mysql ios json


【解决方案1】:

我认为最好只从数据库中获取相关的学生详细信息并将该数据仅存储在数组中。不要使用 select * 来获取所有数据。为学生姓名 + 主键设置一个相似的值并获取该数据集。

UITextField *a = nil, *b = nil, *c = nil, *d = nil, *e = nil;
    NSUInteger idx = 0;

    for ( NSString *string in array )
    {
        switch ( idx++ ) {
            case 0: a.text = string; break;
            case 1: b.text = string; break;
            case 2: c.text = string; break;
            case 3: d.text = string; break;
        }
    }

【讨论】:

    【解决方案2】:

    是的,您可以在文本字段中显示它。尝试使用这种方式。请按照以下步骤操作:

    1. 首先在你的 UIViewController 中初始化全局数组。如下:

      在 yourViewController.h 文件中添加以下代码行:

      NSArray *students_Info;
      
      @property(nonatomic,retain) NSArray *students_Info;
      

      在 yourViewController.m 文件中首先添加以下代码行:

      @synthesize  students_Info;
      
    2. 现在将 JSON 响应中的所有数据添加到 NSMutableArray 中的“students_Info”数组中。

    3. 现在使用 for 循环,您可以通过在 ViewDidLoad 方法中添加以下代码来显示每个文本字段中数组中的所有数据:

      int totalInfo = [students_Info count];
      for(int count=0; count<totalInfo; count++)
      {
         // Display Students Info in each Textfield;
         NSString *studentsFirstName = (NSString *) [[students_Info valueForKey:@"firstName"]objectAtIndex:count];
      
         // Initialize your text field using tag value or some another way and add the text value like above everytime to your each textfield.
      
      }
      

    【讨论】:

    • 在数组计数中我给他们我的最后一个数组索引值显示在按钮单击中而不检查我的字符串
    • 你能分享一些代码吗?..它将帮助我们
    猜你喜欢
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多