search bar and table views are not fitting to the screen in land scape mode
i am creating the search bar and table view programatically using the following code
UISearchBar* searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
UITableView* tblView = [[UITableView alloc]initWithFrame:CGRectMake(0, 41, 320, 400)];
tblView.delegate = self;
tblView.dataSource = self;
[self.view addSubview:tblView];
now i made the return value yes in the following method to to rotate the screen wrt device orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and i used following code in loadView
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
following is my output
but still sear开发者_如何学Goch bar and table views are not fitting to the screen in landscape mode, what should i do can any one help me,,thanx in advanceyou have told the view to resize but you haven't told the search bar you created to resize try something like:
searchbar.autorezingMask = UIViewAutoresizingFlexibleWidth;
do the same for the table view.
see if that gives you the result you are looking for. IF that doesn't work you can always resize the frame of the search bar and table view after rotation.
Try calling this autoresizingMask in ViewWillAppear method.
if you assign frame of any object...you have to provide new frame when it rotates. Give a new frame in following method based on toInterfaceOrientation.
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
精彩评论