[英]What's the best way to load landscape and portrait xib files for uitableviewcells?
我的肖像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];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.