简体   繁体   中英

iPhone Populating Table With UITextFields

Can tables be populated with type 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

Register it in your tableViewController's viewDidLoad:

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

Make sure tableView:cellForRowAtIndexPath: looks something like this:

(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:

- (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.

Hope that helps, Steve

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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