I have a custom UINavigationController that supports auto-rotate. I also have a UIDatePicker on one of my views that I throw onto the stack of the Navigation controller. The a
The below code will work for both portrait and Landscape mode. For this you need to set your tableview frame origin like that below:-
_dateTableViewCell=[self.tableView dequeueReusableCellWithIdentifier:@"DatePickerCell"];
if (self.dateTableViewCell==nil)
{
CGRect rect;
self.dateTableViewCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"DatePickerCell"];
UIDatePicker *datePicker=[[UIDatePicker alloc]initWithFrame:frame];
datePicker.datePickerMode=UIDatePickerModeDateAndTime;
datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
CGRect cellRect = self.dateTableViewCell.frame;
cellRect.size.height = 216;
self.dateTableViewCell.frame = cellRect;
CGRect startRect = self.dateTableViewCell.frame;
startRect.origin.x = 0.0;
datePicker.frame = startRect;
[self.dateTableViewCell.contentView addSubview:datePicker];
}