UITextField在UITableViewCell内部

时间:2012-12-04 07:59:31

标签: iphone objective-c ios ipad

本主题已多次讨论过,我知道如何在UITextField内创建UITableViewCell

我知道使用原型单元格的UITableViewController时,我必须创建一个UITableViewCell的自定义子类,然后通过UITextField挂钩IB进入子类。

为什么使用静态表视图单元格,我必须以编程方式创建UITextField?我找不到使用IB为我的静态表视图单元格创建UITextField的方法。

在使用静态表视图单元格时,尝试拖动并创建UITextField时,界面构建器似乎无用。有谁知道为什么?

我不喜欢使用这样的代码来处理静态单元格,而IB会使用原型单元格为我做这些:

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, -2, 650, 18)];
        textField.placeholder = @"Enter Text";
        [textField setFont:[UIFont fontWithName:@"System" size:16]];
        textField.backgroundColor = [UIColor clearColor];
        textField.delegate = self;
        textField.highlighted = NO;
        cell.accessoryView = textField;
    }

0 个答案:

没有答案
相关问题