原型单元格中的UITextField

时间:2013-11-28 16:28:40

标签: ios uitableview uitextfield

我正在尝试使用TableViewController创建一个原型表,每个单元格中都有一个文本字段。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITextField *teamNumber = nil;
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        teamNumber = [[UITextField alloc]initWithFrame:CGRectMake(45, 30, 200, 40)];
        teamNumber.tag = 100;
        [cell.contentView addSubview:teamNumber];
    }
    else {
        teamNumber = [cell.contentView viewWithTag:100];
    }
    return cell;
}

当我运行模拟器时,没有文本字段。但是,当我用UISwitch替换UITextField(并用CGRectZero替换CGRectMake)时,我看到每个单元格中都有一个开关。有人可以建议吗?

谢谢,

约旦

0 个答案:

没有答案
相关问题