views:

30

answers:

0

I'm using a custom cell in tableView with a 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];
} 

}

This works fine and the UITextField covers the cell.

When i run this with 3.2 sdk or on the iPad the UITextField isn't aligned properly to the left, overlapping the cell and i have to use a UITextField width of 270 instead of 280 UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 270, 24)];

It seems something is wrong the pixel ratio. How can this be fixed? Is there a way to determine the version of os the device has ( 3.1.2, 3.1.3, 3.2 or maybe even the 4.0) or can it be done another way?

Thank you Teo