My portrait tableviewcell doesn't work too well in landscape, even with an autoresize mask so I rearranged things with a new xib file.
What's the best way to implement this new landscape? I got it working using a bunch of if statements checking the orientation, but that doesn't seem too elegant. Is there a better way?
Create two UITableViewCell nib files for portrait and landscape..and one custom class(CustomCell.h and CustomCell.m ) with UITableViewCell as the base class which the two NIB's will inherit and implement the following with your customized cells..
-(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];
}
and then in the tableview datasource
..
- (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];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With