【问题标题】:iPhone Populating Table With UITextFieldsiPhone 使用 UITextFields 填充表格
【发布时间】:2013-05-24 15:19:52
【问题描述】:

可以用 UITextField 类型填充表格吗?如果是这样,如何做到这一点?

我尝试了几种不同的实现,但都失败了。请让我知道您过去是否取得过类似的成就以及您是如何做到的。

【问题讨论】:

    标签: c# iphone xamarin


    【解决方案1】:

    你可以试试MonoTouch.Dialog 效果很好

    【讨论】:

      【解决方案2】:

      创建自定义 UITableViewCell

      在你的 tableViewController 的 viewDidLoad 中注册它:

      [self.tableView registerClass:[TableCell class] forCellReuseIdentifier:@"tableCell"];
      

      确保 tableView:cellForRowAtIndexPath: 看起来像这样:

      (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          static NSString *CellIdentifier = @"tableCell";
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
      
          // Configure the cell...
      
          return cell;
      }
      

      在自定义单元格的 initWithStyle:reuseIdentifier:

      - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
      {
          self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
          if (self) {
              // Initialization code
              [self.contentView setBackgroundColor:[UIColor redColor]];
              UITextField *textField= [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 600, self.bounds.size.height)];
              [textField setBackgroundColor:[UIColor greenColor]];
              [self addSubview:textField];
          }
          return self;
      

      }

      textField 的大小需要调整,自动换行和许多其他实用位也需要调整以使输入和输出正常工作,但这会将 textField 放入 tableViewCell。

      希望对您有所帮助, 史蒂夫

      【讨论】:

        猜你喜欢
        • 2016-03-31
        • 1970-01-01
        • 2015-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多