Вы должны проверить текущую ориентацию в cellForRowAtIndexPath
и правильно настроить ячейку.Вы можете создать 2 разные ячейки с IB.
Кроме того, вам нужно вызвать [myTableView reloadData]
в одном из обратных вызовов для событий вращения (shouldAutorotateToInterfaceOrientation
или didRotateFromInterfaceOrientation
).cellForRowAtIndexPath
будет вызываться каждый раз, когда вы звоните [myTableView reloadData]
(для всех ячеек).Убедитесь, что вы используете разные идентификаторы для повторного использования ячеек.
РЕДАКТИРОВАТЬ: Вот как я бы кодировал это:
Добавьте 2 IBOutlets в ваш файл .h:
IBOutlet MyCustomCell1 * customCell1;
IBOutlet MyCustomCell2 * customCell2;
В Интерфейсном Разработчике установите свойство идентификатора каждой ячейки, может быть что-то вроде cellIdentifier1
и cellIdentifier2
.Убедитесь, что владельцем файла в IB является ваш источник данных (место, где реализовано cellForRowAtIndexPath
).
cellForRowAtIndexPath
должно выглядеть так:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft
|| [UIDevice currentDevice].orientation == UIDeviceOrientationLandscaperight)
{
//Landscape, lets use MyCustomCell2.
NSString * cellIdentifier2 = @"cellIdentifier2";
MyCustomCell2 * cell = (MyCustomCell2 *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
//We have to initialize the cell, we're going to use IB
[[NSBundle mainBundle] loadNibNamed:@"CustomCell2NibName" owner:self options:nil];
//After this, customCell2 we defined in .h is initialized from IB
cell = customCell2;
}
//setup the cell, set text and everything.
return cell;
}
else
{
//portrait case, the same as before but using CustomCell1
NSString * cellIdentifier1 = @"cellIdentifier1";
MyCustomCell1 * cell = (MyCustomCell1 *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
//We have to initialize the cell, we're going to use IB
[[NSBundle mainBundle] loadNibNamed:@"CustomCell1NibName" owner:self options:nil];
//After this, customCell1 we defined in .h is initialized from IB
cell = customCell1;
}
//setup the cell, set text and everything.
return cell;
}
}