1

我在 tableView 中使用带有 UITextField 的自定义单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

    UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 24)];

    txtField.placeholder = @"<Enter Text>";

    txtField.textAlignment = UITextAlignmentLeft;

    txtField.clearButtonMode = UITextFieldViewModeAlways;

    txtField.autocapitalizationType = UITextAutocapitalizationTypeNone;

    txtField.autocorrectionType = UITextAutocorrectionTypeNo;

    [cell.contentView addSubview:txtField];

    [txtField release];
} 

}

这很好用,并且 UITextField 覆盖了单元格。

当我使用 3.2 sdk 或在 iPad 上运行它时,UITextField 未正确对齐到左侧,重叠单元格,我必须使用 270 的 UITextField 宽度而不是 280 UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake (0, 0, 270, 24)];

像素比似乎有问题。如何解决这个问题?有没有办法确定设备的操作系统版本(3.1.2、3.1.3、3.2 甚至可能是 4.0),或者可以通过其他方式完成吗?

谢谢泰奥

4

0 回答 0