iPhone SDK - UITextField subview of UITableCell gives drawing issues?
I'm adding some UITextFields, UITextViews and UIImageViews as subviews to a UITableCell. When I'm entering some text to the TextFields or TextViews and scroll the table up or down, I get some drawing issues. The text of every second field overlaps other fields like this:
I'm creating the form elements like this:
self.formFields = [[NSArray alloc] initWithObj开发者_高级运维ects:
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextView alloc] initWithFrame:CGRectMake(18.0, 8.0, 284.0, 140.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UIImageView alloc] initWithFrame:CGRectMake(18.0, 18.0, 284.0, 284.0)],nil];
And adding the subview:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
[cell addSubview:[self.formFields objectAtIndex:indexPath.section]];
return cell;
}
Is there any way to fix this?
Are you removing the subviews anywhere? If not, they just keep getting added to the cell and appear on top of each other because the cell is being reused. Either remove any old subviews before adding a new one or (this is more logical to me) create different cell identifiers and cells for each section, then create and add the appropriate subview when you create each cell.
精彩评论