【问题标题】:How to use UITextField to input information to UITableView?如何使用 UITextField 向 UITableView 输入信息?
【发布时间】:2013-05-27 06:31:58
【问题描述】:

我正在尝试制作一个待办事项列表应用程序,但我似乎无法弄清楚如何让文本框的键入文本进入一个带有勾选框的框,以便我能够更改为完全的。

谁能帮帮我?我刚刚开始使用 Xcode,所以请解释它为什么/如何以这样的方式工作,以便我将来学习。多谢你们!

应用渲染(我正在尝试做的)

http://imgur.com/wcNXu0z

目前在 Xcode 中(我目前所拥有的)

http://imgur.com/PLUVaVg

【问题讨论】:

  • 到目前为止我还没有尝试过任何太重要的事情。我尝试按照教程将项目添加到表中,但它使用通知警报来输入它并且无法关联。

标签: iphone xcode uitableview uitextfield


【解决方案1】:

您需要为添加按钮创建一个 IBAction。因此,当您单击按钮并将输入的文本存储在 UItextfield 中的数组中时,它会被调用,您将使用该数组在表中添加行。

例如考虑代码:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
       return [dataArray count];
    }


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      static NSString *MyIdentifier = @"MyIdentifier";
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
      if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
      }
      [cell.textLabel setText: [dataArray objectAtIndex:indexPath.row];
      return cell;
    }


    -(IBAction)addCity:(id)sender
    {
      [tableView beginUpdates];
      [dataArray addObject:@"City"];
      NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[dataArray count]-1 inSection:1]];
      [[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
      [tableView endUpdates];
   }

【讨论】:

  • 这应该去哪里?在@implementation 下的.h 或.m 中?我在 .xib 中设置了所有内容,但没有进行任何编码。这是我的 .h 的图像。 gyazo.com/c3e1acda7abaf648115f1e7d7e7d578d 这是我的 .m gyazo.com/8cc8c995edfe9add339184a508e1fcb7 的图片
  • 嘿,先搞清楚你的​​基本情况。浏览创建 UITableView、UIButton、UITextField 和所有内容的基本教程。如何创建这些及其方法和委托的 IBAction 和属性。检查此链接以获取教程raywenderlich.com
  • 该代码将在@implementation下的.m中您需要创建ADD UIButton的IBAction,引用UITableView和UITextField的出口。
【解决方案2】:

我强烈建议您查看免费的 Sensible TableView 框架。该框架应帮助您自动创建文本字段并自动填充/保存其数据。

【讨论】:

  • 这是否允许我添加 UI 自定义以使其看起来像我的渲染?我正在尝试使它与我的 Photoshop 渲染完全一样。
  • 是的,我相信他们有类似 CSS 的主题样式,您可以按照自己的方式为您的应用设置样式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
  • 1970-01-01
相关资源
最近更新 更多