Iphone 什么';为UITableViewCell加载横向和纵向xib文件的最佳方法是什么?
我的肖像tableviewcell在横向环境中工作得不太好,即使使用自动调整大小的掩码,所以我用一个新的xib文件重新安排了内容Iphone 什么';为UITableViewCell加载横向和纵向xib文件的最佳方法是什么?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我的肖像tableviewcell在横向环境中工作得不太好,即使使用自动调整大小的掩码,所以我用一个新的xib文件重新安排了内容 实现这一新局面的最佳方式是什么?我使用了一堆if语句来检查方向,但这看起来不太优雅。有更好的方法吗?为纵向和横向创建两个UITableViewCell nib文件,并创建一个自定义类(CustomCell.h和CustomCell.m),其中UITableViewCell作为基类,这两个nib将继承并使用自定义单元格实现以下功能 -(void) willAnimate
实现这一新局面的最佳方式是什么?我使用了一堆if语句来检查方向,但这看起来不太优雅。有更好的方法吗?为纵向和横向创建两个UITableViewCell nib文件,并创建一个自定义类(CustomCell.h和CustomCell.m),其中UITableViewCell作为基类,这两个nib将继承并使用自定义单元格实现以下功能
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[[NSBundle mainBundle] loadNibNamed:@"customCell-Landscape" owner:self options:nil];
}else
{
[[NSBundle mainBundle] loadNibNamed:@"customCell-Portrait" owner:self options:nil];
}
[tableView reloadData];
}
然后在tableview数据源中
..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @" identifier";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
[[NSBundle mainBundle] loadNibNamed:@"customCell-Landscape" owner:self options:nil];
}else {
[[NSBundle mainBundle] loadNibNamed:@"customCell-Portrait" owner:self options:nil];
}
}
不要忘记为不同的XIB使用不同的单元格标识符名称。我认为不需要在-willAnimateRotationInterfaceOrientation方法中加载自定义单元格nib,只需调用[tableView reloadData];然后在-cellForRowAtIndexPath中加载方便的笔尖