开发者

search bar and table views are not fitting to the screen in land scape mode

开发者 https://www.devze.com 2023-04-01 05:59 出处:网络
i am creating the search bar and table view programatically using the following code UISearchBar* searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];

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

search bar and table views are not fitting to the screen in land scape mode

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 advance


you 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
0

精彩评论

暂无评论...
验证码 换一张
取 消