Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 什么';为UITableViewCell加载横向和纵向xib文件的最佳方法是什么?_Iphone_Objective C_Ios_Uitableview - Fatal编程技术网

Iphone 什么';为UITableViewCell加载横向和纵向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

我的肖像tableviewcell在横向环境中工作得不太好,即使使用自动调整大小的掩码,所以我用一个新的xib文件重新安排了内容


实现这一新局面的最佳方式是什么?我使用了一堆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中加载方便的笔尖