简体   繁体   English

iPhone使用UITextFields填充表

[英]iPhone Populating Table With UITextFields

Can tables be populated with type UITextField? 可以用UITextField类型填充表格吗? If so, how could this be done? 如果是这样,怎么办?

I have attempted a few different implementations, though each failed. 我尝试了几种不同的实现,尽管每种都失败了。 Please let me know if you've achieved something similar in the past and how you did so. 请让我知道您过去是否取得了类似的成就以及您如何取得的成就。

你可以尝试一下MonoTouch.Dialog

Create a custom UITableViewCell 创建一个自定义UITableViewCell

Register it in your tableViewController's viewDidLoad: 在tableViewController的viewDidLoad中注册它:

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

Make sure tableView:cellForRowAtIndexPath: looks something like this: 确保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;
}

In the custom cell's initWithStyle:reuseIdentifier: 在自定义单元格的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;

} }

The textField size needs tweaking, as does the word-wrap and lots of other practical bits to get the input and output working but this gets the textField into the tableViewCell. 需要调整textField的大小,自动换行和许多其他实用位来使输入和输出正常工作,但这会将textField放入tableViewCell中。

Hope that helps, Steve 希望能有所帮助,史蒂夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM