我有 customUITableViewCell
以及页眉和页脚。UITextField
它们中的每一个在排列的列中都有s。这些列的位置是根据UITableView
. (即这样它在横向打开时会利用更宽的屏幕)。
我遇到的问题是当我在视图控制器加载后旋转视图时。UITableViewCell
s 仍然使用旧的定位。
搜索完之后,我现在已经didRotateFromInterfaceOrientation:
在这个方法中实现并重新加载了数据。
现在已经对页眉和页脚进行了排序。但是,UITableViewCell
s 仍然是预先旋转的格式。有没有办法强制表格完全重绘其所有内容?
编辑:我的tableView:cellForIndexPath:
代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
UITextField *TextField1, *TextField2, *TextField3, *TextField4, *TextField5;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
float width = (self.tableView.frame.size.width - 68);
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
TextField1 = [[UITextField alloc] initWithFrame:CGRectMake(((width*position1)+10.0), 10.0, (width*width1), 31.0)];
TextField1.tag = 1;
TextField2 = [[UITextField alloc] initWithFrame:CGRectMake((width*position2), 10.0, (width*width2), 31.0)];
TextField2.tag = 2;
TextField3 = [[UITextField alloc] initWithFrame:CGRectMake((width*position3), 10.0, (width*width3), 31.0)];
TextField3.tag = 3;
TextField4 = [[UITextField alloc] initWithFrame:CGRectMake((width*position4), 10.0, (width*width4), 31.0)];
TextField4.tag = 4;
TextField5 = [[UITextField alloc] initWithFrame:CGRectMake((width*position5), 10.0, ((width*width5)-40.0-editingWidth), 31.0)];
TextField5.tag = 5;
cell.accessoryType = UITableViewCellAccessoryNone;
[cell.contentView addSubview:TextField1];
[cell.contentView addSubview:TextField2];
[cell.contentView addSubview:TextField3];
[cell.contentView addSubview:TextField4];
[cell.contentView addSubview:TextField5];
[TextField1 release];
[TextField2 release];
[TextField3 release];
[TextField4 release];
[TextField5 release];
} else {
TextField1 = (UITextField *)[cell.contentView viewWithTag:1];
TextField2 = (UITextField *)[cell.contentView viewWithTag:2];
TextField3 = (UITextField *)[cell.contentView viewWithTag:3];
TextField4 = (UITextField *)[cell.contentView viewWithTag:4];
TextField5 = (UITextField *)[cell.contentView viewWithTag:5];
}
// Configure the cell...
// Clear cell contents
TextField1.text = @"";
TextField2.text = @"";
TextField3.text = @"";
TextField4.text = @"";
TextField5.text = @"";
int sectionCount = 0;
sectionCount = [workoutSectionsMutableArray count];
// Repopulate cells
NSMutableArray *cellDataArray = [self retrieveCellDataAtIndexPath:indexPath];
TextField1.text = [[cellDataArray objectAtIndex:indexPath.row] 1];
TextField2.text = [[cellDataArray objectAtIndex:indexPath.row] 2];
TextField3.text = [[cellDataArray objectAtIndex:indexPath.row] 3];
TextField4.text = [[cellDataArray objectAtIndex:indexPath.row] 4];
TextField5.text = [[cellDataArray objectAtIndex:indexPath.row] 5];
}
return cell;
}
我的didRotateFromInterfaceOrientation:
方法:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {
[self.tableView reloadData];
}