【发布时间】:2011-04-14 14:37:34
【问题描述】:
我正在使用 UITableView 和 UITableViewCell。 我的应用支持横向,所以我创建了 2 个 UITableViewCell:一个用于纵向,一个用于横向。
在我的 cellForRowAtIndexPath 方法中,这是我的代码
static NSString *CellIdentifier;
static NSString *NibNamed;
UIDeviceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (deviceOrientation != UIDeviceOrientationLandscapeLeft &&
deviceOrientation != UIDeviceOrientationLandscapeRight)
{
CellIdentifier= @"Cell1";
NibNamed = @"cell_news";
}
else
{
CellIdentifier= @"Cell2";
NibNamed = @"cell_news_landscape";
}
[[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:NULL];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:nil];
cell = [nib objectAtIndex:0];
}
///here i add title, description, ecc... in my UITableViewCell
然后在 shouldAutorotateToInterfaceOrientation 我写了这个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[my_table reloadData];
return YES;
}
问题出在哪里? 如果我以纵向启动应用程序,当我第一次旋转设备时,什么也不会发生(并且 UITableCellView 是 Portrait_table_cell)。当我第二次旋转设备时(我处于纵向或倒置状态),我看到了landscape_table_cell(当然,我看不到所有文本,因为它从屏幕上消失了)。 所以.. 除了第一次,我旋转设备的其他时间,我看到了错误的 table_cell_view!!
你知道为什么吗? 谢谢!
【问题讨论】:
标签: iphone uitableview landscape