У меня есть табличный вид в моем контроллере, который настроен на автоматизацию в xibs и отлично работает как с ориентацией, так и с ориентацией на пейзаж. Однако, когда я добавил пользовательский заголовок через код, он не корректно выравнивается с другими ячейками, у моего заголовка есть пользовательская ячейка, которая отображается в таблице как ее подвью. Я пробовал много свойств autoresizingmask, но я просто не могу понять это правильно. Любая помощь будет оценена. Ниже приведены изображения в Lanscape и портретная ориентации и мой код viewcontroller.mTable View Header autoresize issues
#import "ViewController.h"
@interface ViewController()
{
NSMutableArray *tempArray;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
tempArray=[NSMutableArray arrayWithObjects:@"Jack",@"Rose",@"Juliet", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - UITableView Datasource
#pragma mark
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 60.0f;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return tempArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGFloat headerHeight = 40.0f;
NSArray *nib = nil;
nib = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell_iPad" owner:self options:nil];
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, headerHeight)];
[headerView setBackgroundColor:[UIColor clearColor]];
MyCustomCell* mpView = [nib objectAtIndex:0];
[mpView.testLabel setText:@"Name"];
[mpView.testLabel2 setText:@"Age"];
[mpView.testLabel3 setText:@"Date"];
mpView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
[headerView addSubview:mpView];
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60.0f;
}
#pragma mark - UITableView Delegate
#pragma mark
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCustomCell";
MyCustomCell *pCell = (MyCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (pCell == nil)
{
NSArray *nib ;
nib = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell_iPad" owner:self options:nil];
pCell = (MyCustomCell*)[nib objectAtIndex:0];
pCell.backgroundColor = [UIColor clearColor];
}
[pCell.testLabel setText:[tempArray objectAtIndex:indexPath.row]];
return pCell;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_myTable reloadData];
}
@end
Вот ссылка на этот образец проекта http://www.mediafire.com/download/53m6riblk2dkjk7/TableHeaderTest.zip
Я пытаюсь установить autoresize в заголовок, поскольку он не авторезистировал, как другие ячейки – Gamerlegend