我有一个 tableView,我必须根据设备是纵向还是横向来定义不同的单元格高度,但似乎这种方法无法识别设备方向。此方法不起作用:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];//here doesn't recognize the orientation
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
self.tableView.rowHeight =33.33333;
}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight || deviceOrientation==UIInterfaceOrientationLandscapeLeft){
self.tableView.rowHeight = 16.333333;
}
}
else {
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown){
self.tableView.rowHeight = 66.66666;
}else if (deviceOrientation== UIInterfaceOrientationLandscapeRight || deviceOrientation==UIInterfaceOrientationLandscapeLeft){
self.tableView.rowHeight = 33.333333;
}
}
return self.tableView.rowHeight;
}